For instance, to save and read a value from session state, just use the code:
public static void SaveToSession(string s)
HttpContext.Current.Session["abc"] = s;
public static string ReadFromSession()
And what if you want to get a logged user name? It is equally simple, use: HttpContext.Current.User.Identity.Name.
Access to session’s data is possible because when you send requests via the XmlHttpRequest object, the session ID cookie is also included. This cookie looks like this:
* Page Methods are static - and they should be! In this way, Page object creation is avoided and ViewState is not transmitted. The server has less work (no events such as Page_Load or Page_PreRender occur) and the amount of data sent over the network is significantly smaller.