在ASP.NET窗体身份验证自动注销关闭浏览器时 [英] Automatically sign out from Forms Authentication in ASP.NET when browser is closed

查看:84
本文介绍了在ASP.NET窗体身份验证自动注销关闭浏览器时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法强制ASP.NET登出从它的时候关闭浏览器认证或用户键入一个新的地址?

Is there a way to force ASP.NET to sign out from it's authentication when the browser is closed or the user types in a new address?

如果浏览器是开放的话,我需要保持用户身份验证,所以身份验证票证长超时是preferable。

If the browser is left open then I need to keep the user authenticated, so a long timeout on the authentication ticket is preferable.

推荐答案

不知道这仍是一个问题,但这个解决了问题对我来说。只需添加以下到你的起​​始页的Page_Load事件:

Not sure if this is still an issue but this resolved the issue for me. Just add the following to the Page_Load event of your Start Page:

protected void Page_Load(object sender, EventArgs e)
{
    if (Request.UrlReferrer == null || string.IsNullOrEmpty(Request.UrlReferrer.AbsolutePath))
    {
        Session.Abandon();
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
    }
}

这篇关于在ASP.NET窗体身份验证自动注销关闭浏览器时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆