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. 😉



Published by

Alan Feekery

Developer, Gamer, Musician, Cyclist and big Motorsport fan... enjoys the odd cup of coffee :)

One thought on “Accessing Session State from App_Code folder”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s