在我的 MVC 3 应用程序中,我有一个非常基本的 Controller
[HttpPost]
public ActionResult SignIn(LogonModel logonModel)
{
string logonMessage;
if(_authenticationService.Login(logonModel.UserName, logonModel.Password,
out logonMessage))
{
FormsAuthentication.SetAuthCookie(logonModel.UserName,true);
return RedirectToAction("Index", "Home");
}
return View();
}
我看到浏览器中设置了 cookie,但是当我关闭浏览器并返回站点时,它并没有自动让我登录。几乎就像 cookie 没有被处理,它应该被处理。
最佳答案
第一个也是最明显的问题是:您的浏览器是否启用 cookie?
您还可以检查的是,是否在您的 web.config
中,您已经配置了 <authentication>
部分有超时:
<authentication mode="Forms">
<forms loginUrl="~/login" timeout="60" />
</authentication>
如果您不指定超时,它将使用默认值 30 分钟,但也许您将其设置为其他(无效)值?
timeout
属性:
Specifies the time, in integer minutes, after which the cookie expires.
您还可以检查 CookiesSupported
property ( boolean
) 以查看返回结果。
关于asp.net-mvc-3 - FormsAuthentication.SetAuthCookie 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5702824/