注销后禁用浏览器的后退功能 [英] Disabling browser’s back functionality after logout

查看:68
本文介绍了注销后禁用浏览器的后退功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在注销后禁用浏览器的后退按钮。

我已经在注销事件中将会话[session-id]设置为null。

但是当我按下浏览器的后退按钮时,它会将我重定向到我已经注销的安全页面。

请给我任何有关此问题的解决方案。

I want to disable browser's back button after log out.
I have already set session["session-id"] to null on log out event.
But when I am pressing Back button of browser,it will redirect me to that secure page from which I've already log out.
Please Give me any solution about this problem.

推荐答案

看看这个提示:浏览器注销后返回按钮问题 [ ^ ]
Have a look at this Tip: Browser back button issue after logout[^]


我是怎么做的



假设你有一个Login.aspx和Home.aspx以及你在Login.aspx中有登录按钮和Home.aspx中的SignOut按钮;



把它放在页面下加载Login.aspx的事件

Here is how i did it

Assuming that you have a Login.aspx and Home.aspx and Moreover you have "Login" Button in the Login.aspx and a "SignOut" Button in the Home.aspx;

Put this under the Page Load event of the Login.aspx
Session["LoginId"] = null;





将其置于登录按钮的点击事件下[NB。在验证密码后输入此代码]



Put this under the click event of "Login" button [NB. put this code after you validate the password]

Session["LoginId"] = TextBox_UserName.Text;
// TextBox_UserName is the text box on the Login.aspx page that is used to input the username
Response.Redirect("HomePage.aspx");





把它放在Home.aspx的Page Load事件下



Put this under the Page Load event of the Home.aspx

if (!IsPostBack)
    {
       if (Session["LoginId"] == null)
       Response.Redirect("Login.aspx");
       else
       {
          Response.ClearHeaders();
          Response.AddHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
          Response.AddHeader("Pragma", "no-cache");
       }

    }





把它放在SignOut按钮的Click事件下/>



Put this under the Click event of "SignOut" button

try
{
   Session.Abandon();
   Session["LoginId"] = null;
   Response.Cache.SetCacheability(HttpCacheability.NoCache);
   Response.Buffer = true;
   Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
   Response.Expires = -1000;
   Response.CacheControl = "no-cache";
   Response.Redirect("Login.aspx", true);
}
catch (Exception ex)
{
   Response.Write(ex.Message);
}





当用户点击后退按钮并出现Login.aspx页面时会发生以下事件:为了null,所以按下后退按钮再次访问主页将无法打开主页,而是将其重定向到Login.aspx页面。如果用户按下SignOut按钮,后退按钮将其重定向到Login.aspx也是如此。



What happens is that When the user clicks back button and the Login.aspx page appears then the session is set to null so pressing the back button to access the home page again would not open the home page rather it redirects it to the Login.aspx page. Same is true if the user press the "SignOut" button, the back button redirects it to Login.aspx.


Hey Bro ....试试这个



我完全得到了解决方案。





当我们从服务器请求任何页面时,浏览器保持其缓存在本地系统中。当用户按下后退按钮时,在用户面前打开缓存页面。



这意味着我们必须禁用会话页面的缓存功能。因此,您必须将此代码插入会话页面的Page_Load事件或用于安全页面的母版页。

Hey Bro.... try this out

I Perfectly got the solution.


When we request any page from server, browser maintains its cache in local system. When user press back button the cached page opened in front of user.

Its mean we have to disable the cache functionality for our session pages. So for this you have to insert this code into "Page_Load" event of the session page or to master page that is used for secure pages.
Response.Buffer= true;
Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
Response.Expires =-1500;
Response.CacheControl = "no-cache";
if(Session["SessionId"] == null)
{
Response.Redirect ("WhereYouWantToGo.aspx");
}
}



此代码只是禁用当前页面的缓存并将此页面保存在缓冲区中。



并且缓冲区在内存中维护,因此当用户登录时,缓冲区将消耗掉b / b
,并且该页面的备份副本无法查看。 br />


所以它的意思是我们成功禁用了后退按钮。


This code just disable the cache for current page and save this page in buffer.

And buffer is maintained in memory so when user log
out the buffer will
destroy and no backup copy of that page available to view.

So its mean we successfully disable the back button.


这篇关于注销后禁用浏览器的后退功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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