Monday 2 January 2012

Sessions


What are ASP.NET session and compare ASP.NET session with classic ASP session variables?
ASP.NET session caches per user session state. It basically uses "HttpSessionState" class. Following are the limitations in classic ASP sessions :-
1. ASP session state is dependent on IIS process very heavily. So if IIS restarts ASP session variables are also recycled.ASP.NET session can be independent of the hosting environment thus ASP.NET session can maintained even if IIS reboots.
2. ASP session state has no inherent solution to work with Web Farms.ASP.NET session can be stored in state server and SQL SERVER which can support multiple server.
3. ASP session only functions when browser supports cookies.ASP.NET session can be used with browser side cookies or independent of it.
Which various modes of storing ASP.NET session?
1. InProc - In this mode Session state is stored in the memory space of the Aspnet_wp.exe process. This is the default setting. If the IIS reboots or web application restarts then session state is lost.
2. StateServer - In this mode Session state is serialized and stored in a separate process (Aspnet_state.exe); therefore, the state can be stored on a separate computer(a state server).
3. SQL SERVER - In this mode Session state is serialized and stored in a SQL Server database. Session state can be specified in <sessionstate>element of application configuration file. Using State Server and SQL SERVER session state can be shared across web farms but note this comes at speed cost as ASP.NET needs to serialize and deserialize data over network again and again.
Is Session_End event supported in all session modes?
Session_End event occurs only in "Inproc mode"."State Server" and "SQL SERVER" do not have Session_End event.
What are the precautions you will take in order that StateServer Mode work properly ?
Following are the things to remember so that StateServer Mode works properly :-
1. StateServer mode session data is stored in a different process so you must ensure that your objects are serializable.
2. <machinekey> elements in Web.config should be identical across all servers.So this ensures that encryption format is same across all computers.
3. IIS metabase (\LM\W3SVC\2) must be identical across all servers in that farm.

No comments:

Post a Comment