使用浏览器后退按钮进行ASP.NET身份验证登录和注销 [英] ASP.NET authentication login and logout with browser back button

查看:56
本文介绍了使用浏览器后退按钮进行ASP.NET身份验证登录和注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种解决方案,供用户注销后使用浏览器的后退按钮导航到上一页.

I am looking for a solution for user use the browser's back button to navigate to previous page once logged out.

我在asp.net中构建了一个Web应用程序,并使用自定义成员资格提供程序进行身份验证和授权.一切正常,除非用户单击注销链接退出应用程序并重定向到默认封面,如果用户单击浏览器上的返回"按钮,它将实际上返回到之前和之前的位置.数据仍会显示.

I have a web application build in asp.net and using a custom membership provider for authentication and authorization. Everything works fine except when the user click on the logout link to log out of the application and being redirect to a default cover page, if the use click on the BACK BUTTON on their browser, it will actually go back to where they were before and the data will still show up.

当然,他们不能在该页面上执行任何操作,单击任何链接,它们将再次重定向到登录页面.但是,显示这些信息会使很多用户感到困惑.

Of course they can't do anything on that page, click on anything link they will be redirect to a login page again. But having those information display is making a lot users confused.

我只是想知道是否有什么办法可以清除浏览器的历史记录,使使用不能返回,或者当他们单击后退"按钮并将其重定向到登录页面时.

i am just wondering if there is any way i can either clear the browser's history so use can't go BACK, or when they click on the back button and have them redirect to the login page.

谢谢

推荐答案

担心浏览器的历史记录和后退"按钮会让您头疼和尖锐湿疣.有内置的设备可以解决此问题.

Worrying about the browser history and back button is going to give you headaches and genital warts. There are facilities built in to handle this problem.

您的注销链接/按钮应指向包含此代码以及您想要的其他内容的页面.

Your logout link/button should point to a page containing this code, along with whatever else you want.

[vb.net]

Imports System.Web.Security

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles MyBase.Load
    Session.Abandon()
    FormsAuthentication.SignOut()
End Sub

[c#]

using System.Web.Security;

private void Page_Load(object sender, System.EventArgs e)
{
    // Put user code to initialize the page here
    Session.Abandon();
    FormsAuthentication.SignOut();
}

代码来自此页面,但该页面有效眼睛很难.

Code comes from this page and is valid but the page is hard on the eyes.

可以在此处找到有关后退按钮行为的良好问题/答案.

A good Question/Answer regarding backbutton behavior can be found here.

更新:

根据我与Matthew进行的交谈,可以使用如下代码来禁用敏感或易变的单个页面上的缓存:

pursuant to the conversation I am having with Matthew, disabling caching on individual pages that are sensitive or volitile can be done with code such as follows:

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

我很想知道它是否像我一样对您有用.

I am curious to know if it works for you as it does for me.

这篇关于使用浏览器后退按钮进行ASP.NET身份验证登录和注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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