What is Session in ASP.Net?

Session in ASP.Net
  • Session is a length /period of time that a particular browser instance spends accessing a website.
     
  • Session Object - The session object is used to persist data across a user session during the user’s visit to a website. It is almost same as the Context object. When we use Response.Redirect, it causes the Context object to go away, so rather the Session object is used in such a scenario. Session object uses more of server memory than a context object. Example code below shows how to use Session object. 

    Syntax :- Session["sessionname"]=Values;
                      Response.redirect(“pagename.aspx);

    If you want to send a data from ‘send.aspx’ page to ‘receive.aspx’ page.
    First, we have to create a session and then assign value to session.

    Session["Name"]=’MeeraAcademy’;

    Redirect the page to the next page

    Response.redirect(“receive.aspx”);

    After redirecting a page we have to receive that session value in string variable.

    str Name=Session["Name"].ToString();

Leave a Reply

Your email address will not be published. Required fields are marked *

6 + 6 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">