我正在使用ASP.NET MVC,我需要在Application_BeginRequest
上设置会话变量。问题在于此时对象HttpContext.Current.Session
始终是null
。在Application_BeginRequest中设置会话变量
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());
}
}
产品/排序重复的:http://stackoverflow.com/questions/765054/whens-the-earliest-i-can -access-some-session-data-in-global-asax/ – 2013-03-01 05:54:52