【发布时间】:2015-03-11 10:39:57
【问题描述】:
我的 Global.asax 中有以下代码
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
if (HttpContext.Current.Handler is IRequiresSessionState)
{
if (Request.IsAuthenticated)
{
if (HttpContext.Current.Session[this.MemberShipProvider.PrincipalSessionKey] != null)
{
CxPrincipal principal;
try
{
principal = (CxPrincipal)HttpContext.Current.Session[this.MemberShipProvider.PrincipalSessionKey];
}
catch
{
principal = null;
}
HttpContext.Current.User = principal;
Thread.CurrentPrincipal = principal;
}
else
{
var identity = new CxIdentity("admin", 1, "", true);
CxPrincipal principalLogin = new CxPrincipal(identity, 1);
HttpContext.Current.Session[this.MemberShipProvider.PrincipalSessionKey] = principalLogin;
HttpContext.Current.Session[SessionName.CurrentUser] = "Admin User";
HttpContext.Current.User = principalLogin;
Thread.CurrentPrincipal = principalLogin;
this.FormServiceProvider.SignIn("admin", false); // this is equal to FormsAuthentication.SetAuthCookie
}
}
}
}
问题是每次 Session is object 都是空的。不仅在这里,我也不能在我的应用程序中使用会话。会话正在重置或类似的东西。
我的应用程序不再要求用户登录。因此,我没有在我的应用程序的任何地方使用 Session.Clear 或 Session.Abandon。
请帮帮我,为什么我的会话变量没有设置?
【问题讨论】:
-
你的调试告诉了你什么?
-
@AntP 在调试中,我有会话对象但没有设置变量。
-
@Krumelur 你能指导我吗,如果我写课程的地方真的是它的地方吗?
标签: c# asp.net-mvc asp.net-mvc-4 session