I'm using ASP.NET MVC and I need to set a session variable at Application_BeginRequest
. The problem is that at this point the object HttpContext.Current.Session
is always null
.
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.Session != null)
{
//this code is never executed, current session is always null
HttpContext.Current.Session.Add("__MySessionVariable", new object());
}
}
See Question&Answers more detail:os