FormsAuthentication.SignOut()问题 [英] Problem with FormsAuthentication.SignOut()
问题描述
我在进行表单身份验证时遇到问题.当用户关闭浏览器而不点击注销"按钮时,我试图捕获浏览器的点击事件,并使用javascript重定向到会话过期页面,在这里我杀死了Session.Abandon之类的会话.
我在Global.asax中的代码是:
I have a problem with formsauthentication. When the User closes the browser without clicking on Logout button, i tried to capture the browser click events and redirected to session expired page using javascript, where I am killing session like Session.Abandon.
My code in Global.asax is:
void Session_End(object sender, EventArgs e)
{
//**********************************
FormsAuthentication.SignOut();
Session.Abandon();
HttpCookie mycookie = new HttpCookie("ASP.NET_SessionId");
mycookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(mycookie);
}
当我尝试再次打开该URL时,它表明该用户已通过身份验证并且能够查看所有受保护的页面.谁能帮助我解决这个问题.
谢谢,
维沙尔
[修改:添加的代码格式]
When I tried to open the url again, it is showing that the user is authenticated and able to view all secured pages. Can anyone help me on this issue.
Thanks,
Vishal
[Modified: added code formatting]
推荐答案
我想,您需要改善总体设计.没有可靠的方法来知道用户何时关闭浏览器而不注销.您可以尝试使用javascript进行AJAX调用,但这并不可靠.
You need to improve your overall design, I guess. There is no reliable way to know when a user closes the browser without logging out. You can try to use javascript to make an AJAX call, but it''s not reliable.
这篇关于FormsAuthentication.SignOut()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!