65.9K
CodeProject is changing. Read more.
Home

Accessing session from a class file in Asp.Net [For Beginners]

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.78/5 (4 votes)

Apr 13, 2011

CPOL
viewsIcon

47255

For Beginners

The Session property provides programmatic access to the properties and methods of the HttpSessionState class. Because, ASP.NET pages contain a default reference to the System.Web namespace (which contains the HttpContext class), you can reference the members of HttpContext on an .aspx page without the fully qualified class reference to HttpContext. For example, you can use just Session("SessionVariable1") to get or set the value of the session state variable SessionVariable1. However, class file will not inherit System.web namespace. So we need access like below,
HttpContext.Current.Session("Session_Name")     // VB
HttpContext.Current.Session["Session_Name"];    // C#