pyo*_*yon 2 asp.net asp.net-mvc forms-authentication session-state
ASP.NET的会话状态cookie和表单身份验证cookie是两个单独的cookie有什么好的理由吗?如果我想把它们"捆绑"在一起怎么办?有可能以优雅的方式吗?
现在,我坚持使用以下解决方案,这有效,但仍然很难看:
[Authorize]
public ActionResult SomeAction(SomeModel model)
{
// The following four lines must be included in *every* controller action
// that requires the user to be authenticated, defeating the purpose of
// having the Authorize attribute.
if (SomeStaticClass.WasSessionStateLost/*?*/) {
FormsAuthentication.SignOut();
return RedirectToAction("Login", "Account");
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
@ RPM1984:这是发生的事情:
[HttpPost]
public ActionResult Login(LoginModel loginModel)
{
if (/* user ok */)
{
// ...
Session["UserID"] = loginModel.UserID;
Session["Password"] = loginModel.Password;
// ...
}
else
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
并且不需要太多猜测就知道是什么WasSessionStateLost.
会话!=身份验证
会话状态cookie在浏览器会话期间跟踪用户的活动.
窗体身份验证Cookie跟踪用户的身份验证在给定时间内的活动,由票据的到期日,以及是否你已经创建了一个永久性的Cookie(例如,"记住我"复选框)指定.
您不应该触摸会话cookie本身,它包含的所有内容都是将客户端会话(浏览器)绑定到服务器的标识符.
如果您需要访问会话,请使用HttpContext.Current.Session.
你到底想要"绑"到底是什么?
怎么SomeStaticClass.WasSessionStateLost办?
| 归档时间: |
|
| 查看次数: |
853 次 |
| 最近记录: |