Asp.net Session will be used when we need to maintain user level data when user navigating to multiple pages with in the application.Assign value to a session
Reading value from session
There are two types of session modes
- Session In-Process (InProc)
- Session Out-Process (OutProc)
By Default Session state will be saved in-process, i.e. in the system/server memory where the application is running. Mostly we will use inproc sessions because it will give better performance.
Out proc session is two types
- State Server
- SQL Server
If we are using State Server then the session will be maintained by the ASP.NET State server service. so before using this state we should make sure that ASP.NET State server service is running on the server (can be the same server where we hosted the web applciation or can be a different server). If we are using State server mode then the session will be availble even though the web applicaiton is restarted. And can access the same session from multiple web servers. This state will give us less performance compare to Inproc session state.
If we are using the SQL Server as session mode then the session will be stored in SQL Server. So the Session will be still available if the web application is restarted and for the multiple we servers. this will give less performance compare to Inproc session mode and State server session mode.
We can configure the state mode in the web config file. the below example will give you an idea how to do that.
mode : Session mode - Inproc, SQLServer, StateServer
stateConnectionString : if session mode is StateServer then we have to use this tag and set the server connection string.
sqlConnectionString : if session mode is SQLServer then we have to use this tag and set the SQL connection string.