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.
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).
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?
The great thing about binary is even if you are wrong, you are only off by a bit.
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.
Thanx
The great thing about binary is even if you are wrong, you are only off by a bit.
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.
VirtualLife
Member
528 Points
205 Posts
Session resets when saving CSHTML file
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.
Thanx.
BrockAllen
All-Star
28052 Points
4996 Posts
MVP
Re: Session resets when saving CSHTML file
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.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
Rion William...
All-Star
31882 Points
5191 Posts
Re: Session resets when saving CSHTML file
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).
VirtualLife
Member
528 Points
205 Posts
Re: Session resets when saving CSHTML file
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?
BrockAllen
All-Star
28052 Points
4996 Posts
MVP
Re: Session resets when saving CSHTML file
Jan 17, 2013 07:21 PM|LINK
<session mode='StateServer'> or <session mode='SqlServer'>
http://msdn.microsoft.com/en-us/library/87069683%28v=vs.71%29.aspx
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
VirtualLife
Member
528 Points
205 Posts
Re: Session resets when saving CSHTML file
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.
Thanx
BrockAllen
All-Star
28052 Points
4996 Posts
MVP
Re: Session resets when saving CSHTML file
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:
http://blogs.msdn.com/b/tess/archive/2006/08/02/686373.aspx
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/