Reputation: 14694
I'm setting a Session
in my Asp.NET Code like this:
public class MyController : Controller
{
public ActionResult Index()
{
Session["AdminID"] = id;
return View();
}
}
But now I want to access this Session
in a file which is not a Controller
in the background of the project.
Is this possible?
S.th. like this:
public class MyClass
{
public int Foo()
{
return Session["AdminID"]
}
}
Upvotes: 0
Views: 64
Reputation: 5128
Use HttpContext.Current.Session
:
using System.Web;
// ...
public int Foo()
{
return (int)HttpContext.Current.Session["AdminID"];
}
Upvotes: 3