开发者

In ASP.NET MVC why might TempData not persist when Session does?

开发者 https://www.devze.com 2023-02-25 06:32 出处:网络
I have an ASP.NET MVC project which uses TempData to carry an object from one controller action to another - which is in fact the same action but a version that accepts HTTP posts.

I have an ASP.NET MVC project which uses TempData to carry an object from one controller action to another - which is in fact the same action but a version that accepts HTTP posts.

On my development machine this works as expected. On the test machine the TempData value is null in the second controller action.

Forum posts which I've seen suggest checking that sessionState is working - which I have done. Both websites have sessionState set to InProc - neither web.config contains a sessionState entry but I've checked that Session.Mode is InProc. If I put an object in Session in the first controller action I can retrieve it in the second on both machines.

I can work around this by re-doing the process u开发者_开发技巧sed to set TempData in the first controller action in the second but why might TempData be being lost on the test machine?


Make sure you aren't reading it from say - a layout (master page) an extra time. To be sure, wrap the call where you set/get this values and write trace information out to make sure you are only calling it when you expect. I had a similar issue on an app a while back (mvc2) and it turned out I was reading it when it first seemed I wasn't.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号