Modes of session state?

Session

Session is saved on the server. Default is inproc. you can control how this session information is to be saved on the server. Per user per browser separate session is created and session is specific to user. A session is identified by sessionid. by default the sessionid is maintained by cookies. if cookies are disabled on clients machine sessionid is maintained by modified url. The mode of session state settings allow you to configure  what session state provider is used to store session state information between requests.  The available Mode options are:

Off :   The setting disables session stste management for every page in the application. This can provide a slight performance improvement for websites that are not using session state.

InProc :  InProc is similar to how session state was stored in classic asp. It instructs ASP.net  to store information in the current application domain.  This provides the best performance but the least durability.  If you restart the server , the state information will be lost.

StateServer:  With this ASPNET will use a separate windows service for state management.

Sqlserver

None

Custom

Session state works on some browsers, but not on others. Why?

Assume you aren't using cookieless, you should make sure your browsers support cookie.

Session states works on some web servers but not on others.
Maybe machine name problem. 

Why isn't session state available?

- First, check your web.config, machine.config and your page directive to make sure you have enabled session state.

-Also, please note that session state isn't available just everywhere, anytime.  It is available only after the HttpApplication.AcquireRequestState event is called.  For example, it is NOT available in the Application_OnAuthenticateRequest handler inside global.asax.

-Lastly, make sure System.Web.SessionState.SessionStateModule is included the <httpModules> in your config files.  A common case is that SharePoint application will remove this module from their web.config files (for performance reason), and thus session state isn't available.

What is the difference between Session.Abandon() and Session.Clear()?
The major practical difference is that if you call Session.Abandon(), Session_End will be fired (for InProc mode), and in the next request, Session_Start will be fired. Session.Clear( ) just clears the session data without killing it.

What kinds of object can I store in session state?
It depends on which mode you are using:
- If you are using InProc mode, objects stored in session state are actually live objects, and so you can store whatever object you have created.
- If you are using State Server or SQL Server mode, objects in the session state will be serialized and deserialized when a request is processed.  So make sure your objects are serializable and their classes must be marked as so.  If not, the session state will not be saved successfully.  In v1, there is a bug which makes the problem happen unnoticed in  SQLServer mode and will make your request hang.  The hanging problem is fixed in v1.1.  The QFE fix for KB 324479 also contains the fix for this problem.  The problem will be fixed in v1 SP3 too.

Why isn't Session_End fired?
This is one of the most frequently asked question.
1. Remember Session_End event is supported only in InProc mode. 
2. Session_End won't be fired if you close your browser. HTTP is a stateless protocol, and the server has no way to know if your browser has closed or not.
3. Session_End will be fired only (i) after n minutes of inactivity (n = timeout value), or (ii) if someone calls Session.Abandon().
4. For case (i) (pt. 3), Session_End will be run by a background thread, which implies:
    a. Your code in Session_End is running using the worker process account. You may have permission problem if you're accessing resource such as database.
    b. If an error happens in Session_End, it will fail silently.
5. For case (ii), please note that in order for Session_End to be fired, your session state has to exist first.  That means you have to store some data in the session state and has completed at least one request.  
6. Again for case (ii), Session_End will be called only if the abandoned session is actually found. As a result, if you create and abandon a session inside the same request, because the session hasn't been saved and thus can't be found, Session_End won't be called.  This is a bug in v1 and upcoming v1.1.

 


Modes of session state off inProc stateserver modes of session state disables session session settings state management enabled session Session.Abandon Session.Clear Session_End