Namespace SessionState doesn't work
-
using System.Web.SessionState; In Forms I can access methodes and properties of the Session object. But in pure classes it looks like it doesn't work really. I tried other web namespaces but it doesn't work. Is there a way accessing Session object in non form classes ?
-
using System.Web.SessionState; In Forms I can access methodes and properties of the Session object. But in pure classes it looks like it doesn't work really. I tried other web namespaces but it doesn't work. Is there a way accessing Session object in non form classes ?
The reason you can freely use the Session instance in a web page is that the ASP.NET page basically contains a default reference to the System.Web namespace, then you can use the Session object without specifying the fully qualified class name. In other classes, you must include a reference to the System.Web namespace and use the full name HttpContext.Current.Session to get/set a value, for example:
HttpContext.Current.Session["MyVariable"] = value;