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

查看:30
本文介绍了使用浏览器后退按钮进行 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天全站免登陆