我正在使用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());
}
}