【发布时间】:2011-08-24 01:16:01
【问题描述】:
我正在使用 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());
}
}
【问题讨论】:
-
相关/类似以下内容的副本:stackoverflow.com/questions/765054/…
标签: asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-2 global-asax