Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 18, 2013 12:10 AM by BrockAllen
Jan 17, 2013 04:27 PM|LINK
I am running everything locally on IIS express with the default settings using MVC 3.
If I save a cshtml file, my session gets reset. Never seen this before and can't seem to track it down. Any ideas would be great.
Jan 17, 2013 04:53 PM|LINK
Saving the .cshtml causes a recompilation and thus potentially an appdoamin recycle. It's how ASP.NET works. You need to decouple your session state from the lifecycle of the web host process.
Jan 17, 2013 05:01 PM|LINK
Saving or updating will typically cause your application to re-compile (and additionally your application domain). Either of these will likely reset your Session state (thus removing your Session-related data).
Jan 17, 2013 05:55 PM|LINK
I have never had a non compiled file other than the web.config reset a session on change. But ok, I'll bite. How do you decouple session state from the lifecycle?
Jan 17, 2013 07:21 PM|LINK
<session mode='StateServer'> or <session mode='SqlServer'>
Jan 17, 2013 08:31 PM|LINK
Ah ok change the session type. Thanks.
I would still like to know why this doesn't always happen so if anyone reads this down the road and has an answer, please let me know. This project takes minutes to compile, so doing layout changes can take hours with it loosing the session most of the time.
Jan 18, 2013 12:10 AM|LINK
Well, in general if anything that resides in ~/bin changes this triggers a recycle. If web.config changes -- recycle. If there's too much memory being used -- recycle. If one of the IIS app pool recycle thresholds is crossed -- recycle. And, if too many
on-demand compiled files need recompiling -- recycle. This last one is necessary because if you think about it you'd not want the .cshtml files to get recompiled too much since each recompile produces a new assembly that's loaded into the app domain. Assemblies
can't be unloaded once loaded, so there's some threshold at which the app domain says "too many DLLs, let's start over" and recycles.
Here's a more detailed post on what causes it: