Accessing Session State from App_Code folder

Adding functionality to your ASP.NET web pages from your App_Code folder is probably my favourite feature of ASP.NET Web Forms, however you might have noticed that you cannot not access session state from your .cs files as easily as you might from a code behind file.

Thankfully it is quite easy to get a hold of current session state data from your application.

Add in this using statement to your cs file:

using System.Web.SessionState;

Then create a handle to the current session state data:

HttpSessionState Session = HttpContext.Current.Session;

And your done, work with the Session var now just like you would in your code behind files. ;)

Resource: forums.asp.net

blog comments powered by Disqus