[英]Simple membership provider, AccountController and auth cookie ASP.Net MVC 4
只需查看默认代码即可验证用户:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl) {
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) {
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
当用户通过验证后,用户将被重定向到视图,但是没有auth cookie
被丢弃在用户pc中,因为我没有找到用于此的代码。
所以告诉我WebSecurity.Login()
函数是在内部执行的还是需要编写代码以在用户PC中删除auth cookie
?
WebSecurity.Login()添加具有以下名称的会话Cookie:.ASPXAUTH。
从MSDN站点:( https://msdn.microsoft.com/zh-cn/library/webmatrix.webdata.websecurity.login ( v=vs.111 ) .aspx )
public static bool Login(
string userName,
string password,
bool persistCookie
)
userName类型:System.String用户名。
password类型:System.String密码。
persistCookie类型:System.Boolean(可选)为true,用于指定cookie中的身份验证令牌应保留在当前会话之后;否则为false。 否则为假。 默认值为false 。
当用户登录时,ASP.NET在cookie中设置一个身份验证令牌,该令牌使ASP.NET在后续请求中知道该用户已登录。如果persistCookie为false,则该令牌仅在用户关闭浏览器之前有效。 。
您无需添加任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.