In this article describe the concept of the In-proc session state mode in Here we understand the In-proc session state mode and learn from the example.

Web is stateless, which means a new instance of a web page class is re-created each time the page is posted to the server. As we all know, HTTP is a stateless protocol, it can't hold client information on a page. If the user inserts some information and move to the next page, that data will be lost and the user would not be able to retrieve that information. What do we need here? We need to store information. Session provides a facility to store information on server memory. It can support any type of object to store along with our own custom objects. For every client, session data is stored separately, which means session data is stored on a per client basis.

ASP and ASP.NET applications maintain a user’s session using a feature called session state.

ASP.NET supports various Session State Modes depending on various storage options for session data. The following are the available Session State Modes in ASP.NET:

·         InProc

·         StateServer

·         SQLServer

·         Custom

Let’s we talk about In-proc session or In-process mode session in

The In-proc session state mode is the default session state mode. This is the best session mode for web application performance. But the main disadvantage is that, it will lose data if we restart the server. In-proc session mode stores its session data in a memory object on the application domain. This is handled by a worker process in the application pool. So if we restart the server, we will lose the session data. If the client request for data, the state provider read the data from an in-memory object and returns it to the client. In web.config, we have to mention the session mode and also set the timeout.

ASP.NET provides two events that help you manage user sessions. These events are defined in the Global.asax file of the web application.

·         Session_Start() : This event occurs when a new session begins.

·         Session_End() : This event occurs when a session is abandoned or expires.

In in-proc session state mode is only supports the Session_End() event. The general flow for the InProc session state is like this:

In-proc session state in

In the in-proc session state mode is the default session state mode but you can also set the session state mode and session timeout in the web.config file in your application in following code:

    <sessionState mode="InProc" timeout="25"></sessionState>

If you don’t define timeout it is by default 20 minutes.

Here we give the example to understand in-proc session state mode.

Step 1

Here we the create user form (User.aspx):

<form id="form1" runat="server">


        <table style="width: 34%;">


                <th>First Name</th>


                <td><asp:TextBox ID="txt_firstname" runat="server" Width="144px"></asp:TextBox></td>



                <th>Last Name</th>


                <td><asp:TextBox ID="txt_lastname" runat="server" Width="144px"></asp:TextBox></td>



                <th class="auto-style1">E-mail</th>


                <td class="auto-style2"><asp:TextBox ID="txt_email" runat="server"Width="144px"></asp:TextBox></td>





                <td><asp:Button ID="btn_Submit" runat="server" Text="Submit"OnClick="btn_Submit_Click" /></td>





Step 2

Write code behind on submit button:

protected void btn_Submit_Click(object sender, EventArgs e)


        Session["FirstName"] = txt_firstname.Text;

        Session["LastName"] = txt_lastname.Text;

        Session["E-mail"] = txt_email.Text;



Step 3

Code into the UserDetail.aspx on page load:


protected void Page_Load(object sender, EventArgs e)




            string firstname = Session["FirstName"].ToString();

            string lastname = Session["LastName"].ToString();

            string email = Session["E-mail"].ToString();

            Response.Write(string.Format("User First name is :{0}<br />", firstname));

            Response.Write(string.Format("User Last name is :{0}<br />", lastname));

            Response.Write(string.Format("User E-mail  is :{0}", email));


        catch (NullReferenceException ex)


            Response.Write(ex.Message + " Becasue Session doesn't exist");



Step 4

Run the InprocSessionExample web application:

In-proc session state in

If the server will be closed then the inproc session state mode store value will be


In-proc session state in

Advantage of in-proc session state mode

·         Easy to implement

·         Stores the session data on the server so it is fast. 

Disadvantage of in-proc session state mode

·     When the application domain or worker process recycles, the session data

will be lost.

·      It is usually the fastest, but more session data means more memory is used

on the web server, and that can affect performance

  Modified On Mar-24-2018 02:48:58 AM

Leave Comment