Tuesday, July 28, 2009

How can I access the session or application object in my .cs file. I am using C# & asp.net 2.0?

I am not able to access the session or application object in my .cs file. I am using C# %26amp; asp.net on .net 2.0.Its not showing Session or Application object in the editor drop down list too.

How can I access the session or application object in my .cs file. I am using C# %26amp; asp.net 2.0?
Is you CS file part of the web application or is it in another class library?





If it is in another class library you should reference the System.Web dll first then in your code you will be able to access the Session through:


System. Web. HttpContext. Current. Session["key"]





If you CS file is in your web application you just access the object


Session["key"]





In both cases you'll have to cast to your type from object.





Hope this helps.


No comments:

Post a Comment