简体   繁体   中英

ASP .NET / Read Only Session / Allows Writing

I notice this post on a similar topic:

ASP.NET -> WCF concurrency problem

I just went ahead and added the:

HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.ReadOnly);

directive to my HttpModule in the AuthenticateRequest event. Later on, in my handling code, I call:

HttpContext.Current.Session["value"] = "1";

This set succeeds and the value is there on the next request. Does anyone have any idea why I don't get an exception thrown here? I am using MVC 5, .NET 4.5 and used Visual Studio 2013 to compile my application in debug mode.

I am not sure, but I think maybe AuthenticateRequest is a bit too late to set this. Try setting it in BeginRequest instead.

ref the Internet (eg http://abhijitjana.net/2011/01/15/programmatically-changing-session-state-behavior-in-asp-net-4-0/ ) and ASP.NET Application Life Cycle Overview for IIS 7.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM