Asp.Net session State Why to use with Example

Introduction :

   Session is Defined as it is time duration from the user can login the application to while it exit from the application. During this session time duration it can pass the session data from one page to another many page..

 Session can identify the each user uniqually and not need to retrieve the session data from the database thus  it can make the process fast. session also store the user history form which time user are login and exit from the system.

Advantage of session :

*  Session can store Client data separately

* Used for security purpose 

* Identify each user Uniqlly

*Fast transference data from one page to another page

Disadvantage Of Session :

* When Session store large data occurs problem of performance overhead because session data are store in
  server side thus it increase the load of server.


How to Store and retrieve Session : 

Session value can be store and retrieve same as ViewState.but we are discuss  syntax of session how to 
used for passing the session from one page to another and how to retrieve to another page.

 * Code For Storing the session value :
       
Session["UName"] = txtUName.Text;

How to retrieve Session :

if (Session["UName"] != null)
{
    //Here we can retrieve User from Session and display in label
     lbl.Text = "Welcom : " + Session["UName"];
}

*  Session have default time duration 20 minutes.

* And we can also set session expire time in web.config file as the following

  <system.web>
               // Here define session timeout
         <sessionState  mode="Inproc"  timeout="30"/>
</system.web>



See Other Tutorial :

AngularJS CRUD Operation : Select Insert Edit Update and Delete using AngularJS in ASP.Net MVC

*  AngularJS With ASP.NET MVC

*  Convert Rows to columns using 'Pivot' in SQL Server

*  Mvc Registration page With user exist using Ajax method

*  MVC 4 How to Perform Insert Update Delete Edit Select Operation

*  MVC4 Edit,update,Delete,cancel inside gridview using sql database


*  MVC 4 Gridview To Display Data Using SQL Server Database With Simple code


*  Login page in asp.net Mvc4 Web application


*  Mvc4 How to bind Dropdown List using Sql Database


Gridview find control in asp.net
Previous
Next Post »