Home > Interview Questions > ASP.NET > What is the use of session state in asp.net?

What is the use of session state in asp.net?

by Thamil   on 05/10/2015   Category: ASP.NET   |  Level: Advance   |  Views: 761    |  Points: 25     |  Gold 


Session state in asp.net used to allows user to store and retrieve values while navigating the web pages. Actually web is stateless, new instance of the web page will be created for each and every request. So every post back page is recreated and loaded in the browser, so asp.net provides state management to maintain pages data while post back and session state is one of the state management to store and retrieve the values.
//Store values into session
Session["FullName"] = FirstNameTextBox.Text +””+ LastNameTextBox.Text;
//Get values from session
String FullName = Session["FullName"]. .ToString();

Asp.net session state provides the different type of storage options for session data to store.
Inproc: Store all the session data in the in memory of web server.
SQLserver: store the session data in SQL server and configuration needs to be applied in web.config file.
Custom: Need to provide the users custom storage provider to store all session data.
Off: Used to disable the session state for the application.
StateServer: Used to store the session data in asp.net state service process and session data would be preserved even if web application is restarted.

Sample session state configuration web.config file
<configuration>
<sessionstate mode="inproc" cookieless="false" timeout="20"
sqlconnectionstring="data source=;user id=<user id>;password=<password>"
server="" port="" />
</configuration>



« How do you get last exception in asp.net?
» What is reference directive in asp.net?
Post Question  |  Question Home

Recent Posts

User Responses


No response found, be the first to review this question.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts