Session object usage in ASP.NET
page1.aspx
protected void Page_Load(object sender, EventArgs e)
{
Session["User"]="rockone";
}
page2.aspx
protected void Page_Load(object sender, EventArgs e)
{
//need to type cast to String otherwise it returns object type
String user = (String)Session["User"];
}
Sequence: first run page1.aspx , next page2.aspx.
Get SessionID
Session ID is associated with browser instance
Response.Write(Session.SessionID);
Sessions can be stored in Inproc, Out-proc(STATE SERVER), or in sql-server OR IN CUSTOM
No comments:
Post a Comment