问题描述
我想实现注销功能在ASP.NET MVC。
I am trying to implement Logout Functionality in ASP.NET MVC.
我用表单验证我的项目。
I use Forms Authentication for my project.
这是我退出code:
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");
这code将用户重定向到登录屏幕。但是,如果我叫在地址栏中指定名称的操作方法(或选择$ P $从地址栏下拉pvious链接),我仍然能够达到安全页面没有登录。
This code redirects the user to the Login Screen. However, if I call an action method by specifying the name in address bar (or select the previous link from address bar dropdown), I am still able to reach the secure pages without logging in.
有人能帮助我解决这个问题?
Could someone help me solve the issue?
推荐答案
这是很奇怪......我做一个单一的呼叫:FormsAuthentication.SignOut();和它的作品...
That's strange... I make one single call to: FormsAuthentication.SignOut(); and it works...
public ActionResult Logout() {
FormsAuthentication.SignOut();
return Redirect("~/");
}
这篇关于无法使用FormsAuthentication.SignOut的ASP.NET MVC应用程序退出()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!