Session variables inside of App_code classes

Hi all,

I have a series of C# classes in my app_code that are called during the running of my ASP.NET application. And sometimes I would like to set Session variables inside of thse classes. But I don’t seem to have access to the session variables.

And it seems to make sense, because these classes are not really able to access like the HTTP variables (if that even make sense).

So I was wondering is there a way to access session variables from inside a C# class. I am thinking I have to send it a HTTPContext object as parameter to the method. But if that is the case, how I prepare the HTTPContext object.

Hope this makes sense.

Any help would be great. Thanks

The HttpContext object has singleton based access thus…


[SIZE=1][COLOR=#2b91af][SIZE=2][COLOR=black]string sessionData = HttpContext[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][SIZE=2][COLOR=black].Current.Session["sessionKey"];[/COLOR][/SIZE]
[/SIZE]

You can access it anywhere in any object so long as it is running in the context of a web application and the code references the System.Web.dll. Basically this means that you do not have to pass a reference to it around your web site.

thanks!