Click here to Skip to main content
Click here to Skip to main content

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

By , 13 Apr 2011
 
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#

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Toniyo Jackson
Software Developer
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionGetting an errormemberJesse Fatherree16 Oct '12 - 11:02 
GeneralReason for my vote of 5 Good for beginners.mvpKunal_Chowdhury13 Apr '11 - 1:44 
GeneralRe: Thanks KunalmemberToniyo Jackson13 Apr '11 - 20:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 13 Apr 2011
Article Copyright 2011 by Toniyo Jackson
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid