3
Reply

What is session? How do you initialize a session and how you declare it?

Anshu Kumar

Anshu Kumar

5y
8.1k
0
Reply

    Session Declaration is all follow
    {
    Session[“UserName”]=”Vaibhav”;
    }

    Use declared session like
    {
    string Name =(string)Session[“UserName”];
    }

    Declare :
    Session[“userId”]=”1”;
    Retrive:
    string userId =(string)Session[“userId”];

    Session is a cookie variable in server and it is handle in server level in our entire web technologies (asp.net,asp.net mvc).

    1. in asp.net
      1. System.web.HttpContext httpcontext= new System.web.HttpContext();
      2. httpcontext.Current.Requiest.Session["variable_name"]="variable_value";
    2. in Asp.net MVC
      1. Session["variable_name"]="Session value";
      I hope above is ok our understanding purpose.