我正在尝试在 ASP.NET MVC 中实现注销功能。
我为我的项目使用表单例份验证。
这是我的注销代码:
FormsAuthentication.SignOut();
Response.Cookies.Clear();
FormsAuthenticationTicket ticket =
new FormsAuthenticationTicket(
1,
FormsAuthentication.FormsCookieName,
DateTime.Today.AddYears(-1),
DateTime.Today.AddYears(-2),
true,
string.Empty);
Response.Cookies[FormsAuthentication.FormsCookieName].Value =
FormsAuthentication.Encrypt(ticket);
Response.Cookies[FormsAuthentication.FormsCookieName].Expires =
DateTime.Today.AddYears(-2);
return Redirect("LogOn");
此代码将用户重定向到登录屏幕。但是,如果我通过在地址栏中指定名称(或从地址栏下拉列表中选择上一个链接)来调用操作方法,我仍然可以在不登录的情况下访问安全页面。
有人可以帮我解决这个问题吗?
最佳答案
这很奇怪...我只调用了一次:FormsAuthentication.SignOut();并且有效...
public ActionResult Logout() {
FormsAuthentication.SignOut();
return Redirect("~/");
}
关于c# - 无法使用 FormsAuthentication.SignOut() 从 ASP.NET MVC 应用程序注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3889380/