Saturday, July 21, 2007

State Management : Session State Read Write Values

Add Object to the Session State:
HttpSessionState.Session.Add(name, Value)

Assign a value to a Session object
HttpSessionState.Session["UserName”] = “Sg”;

Reading from a session object:
string userName = HttpSessionState.Session["UserName”].ToString();

Remove an object from session:
HttpSessionState.Remove(objName);

Clear the session
Session.Abandon() or Session.Clear()
Session.Abandon : Calls Session_End will be fired
Session.Clear : Just clears the session data without killing it

Enable/Disable Session state at Page Level:
Page Level : <%@ Page EnableSessionState=”False” %>
Page Level ReadOnly : <%@ Page EnableSessionState=”ReadOnly” %>

No comments: