In Asp.net Programmatically Change Session State Behavior

In asp.net Programmatically Change Session State Behavior when required:



In Asp.net it is possible to change the value of session at run time. Before some time when we worked on asp.net project we want to something like that then we search this topic on web and get something like that. I thing you also get some help from this programmatically change state behavior in asp.net topic.

We can enable or disable session state either in web.config or using @Page directive’s EnableSessionState attributes.

But there was no provision to change the session state at runtime till date in ASP.NET. But using ASP.NET 4.0, we can change the session state programmatically. The .NET 4.0 Framework adds a new method SetSessionStateBehavior to the HttpContext class for ASP.NET. 

This method required SessionStatebehavior value to set the current session mode. To call SetSessionStateBehavior, simply create a new HttpModule by implementing IHttModule and hook the BeginRequest event. Most important, you can only use the SetSessionStateBehavior until the AcquireRequestState event is fired, because AcquireRequestState occurs when ASP.NET acquires the current state that is associated with the current request.

While calling SetSessionStatebehavior, you can pass the following values as SessionStatebehavior:


Default: This is the default setting which means everything works as before.
Disabled: Turned of Session Sate for Current Request.
ReadOnly: Read only access to Session State.
Required: Enabled session state for both Read and Write Access.


Other Asp.net Related Post: 






Comments