我想知道如何在窗体身份验证中使用会话ID?因为我在家里的控制器上做了一个Response.Write(Session.SessionID);
,然后注销。然后,我以新用户的身份登录并且会话ID相同。下面是我的登录和注销操作:ASP.NET MVC - 表单身份验证/会话ID
登录:
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
try
{
if (ModelState.IsValid)
{
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
return View("LogonError", model);
}
catch (Exception ex)
{
string test = ex.Message;
return PartialView("_Error", test);
}
}
注销等:
public ActionResult LogOff()
{
FormsAuthentication.SignOut();
return RedirectToAction("Index", "Home");
}
有2周不同的Cookie用于认证和会话。 – Believe2014 2014-06-02 02:41:09