我在用ASP.NET MVC和我需要将会话变量设置为Application_BeginRequest
.问题是,在这一点上,对象HttpContext.Current.Session
始终是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());
}
}