advantages of Session State

Session in asp.net & Advantages of Session:



In this post we describe advantages and disadvantages of session management. And also Explain how to make and use session in asp.net page.

The advantages of using Session State

  • Better security
  • Reduced bandwidth

The disadvantages of using Session state are

  • More resource consumption of server.
  • Extra code/care if a Web farm is used.

Using Session State in asp.net:

ASP.NET allows us to save values using Session state. It is a global storage mechanism that is accessible from all pages in the Web application. Session state is stored in the Session key/value dictionary. This information will be user specific i.e. for each user separate dictionary will be created and no one can access other session information. Below is the Example usage of sessions.
// write in global.asax
void Session_Start(object sender, EventArgs e)
{
    // Code that runs when a new session is started
    Session["number"] = 0;
}

// write in Web forms
Session["number"] = Convert.ToInt32(Session["number"]) + 1;
Label6.Text = Session["number"].ToString();

Enumerating Session Management Techniques:

Before we proceed, let us see what all session management techniques are present in the ASP.NET framework.
  • In-Proc.
  • SQLServer.
  • StateServer.

Configure Sessions in asp.net:

To configure the session management we need to specify the settings in the web.config file. Typical settings in web.config looks like:

<sessionState mode="InProc"
                stateConnectionString="tcpip=127.0.0.1:42424"
                sqlConnectionString="Data Source=.\SQLEXPRESS;Trusted_Connection=Yes;"
                cookieless="false"
                timeout="100"/>


Now see what each of these attributes mean:

We explain all terms here.
Mode:
                This specifies the type of session management we want to use. It could be InProc, SQL Server, and State Server.
If we use State Server as session management technique then this specifies the location of the server that is handling the session data.

sqlConnectionString:
If we use SQL Server as session management technique then this specifies the database connection string that will store the session data.

cookieless:
                This specifies whether we will be using cookies to identify sessions or we want session info appended in URL. It could be true or false.

timeout :

Comments

Popular posts from this blog