注销按钮代码... [英] logout button code...

查看:71
本文介绍了注销按钮代码...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码注销按钮。它正在工作,但是有一个问题是它禁用了所有页面的后退按钮。我想在用户注销时仅在登录页面上禁用后退按钮..



请帮助我...


$注销按钮点击事件的b $ b代码:

I am using the following code for the logout button. It is working but there is a problem that it disable the back button for all the pages. i want to disable back button only on login page when user logouts..

please help me...

code on click event of logout button:

protected void logout_button_Click(object sender, ImageClickEventArgs e)
    {
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Cache.SetNoServerCaching();
        HttpContext.Current.Response.Cache.SetNoStore();
        Session.Abandon();
        Session.Clear();
        Response.Redirect("~/login.aspx");
    }





javascript:





javascript:

window.history.forward(1);
    document.attachEvent("onkeydown", my_onkeydown_handler);
    function my_onkeydown_handler() {
        switch (event.keyCode) {
            case 116: // F5;
                event.returnValue = false;
                event.keyCode = 0;
                window.status = "We have disabled F5";
                break;
        }
    }

推荐答案

请按照以下资源。



1. 退出后浏览器返回按钮问题 [ ^ ] 。

2. 如何防止在asp.net注销后退回按钮 [ ^ ]。

3. 使用JavaScript在ASP.Net中LogOut之后的禁用浏览器后退按钮 [ ^ ]。
Please follow the below resources.

1. Browser back button issue after logout[^].
2. how to prevent back button after logout in asp.net[^].
3. Disable Browser Back Button after LogOut in ASP.Net using JavaScript[^].


在页面上使用以下代码,以防止使用后退按钮着陆



Use the below code on the page which you want to prevent to be landed using back button

<script type="text/javascript">
  function preventBack() { window.history.forward(); }
  setTimeout("preventBack()", 0);
  window.onunload = function() { null };
</script>

<script language="JavaScript" type="text/javascript">
  javascript: window.history.forward(1);
</script>





代码中的更正:[附加]





Correction in your code:[Additional]

Session.Abandon();
Session.Clear();\\Not required





因为放弃你的会话所以没有必要清除它。



问候..:)



Becuase Abandon has already thrown your session so no need to clear it.

Regards.. :)


引用:

我想在用户注销时只在登录页面上禁用后退按钮

I want to disable back button only on login page when user logouts



不,你无法在任何条件下禁用浏览器的后退按钮。您需要重新考虑应用程序逻辑,以便用户按下后退按钮无关紧要。不要试图弄乱浏览器。它或者只是偶尔工作,然后,只针对那些启用了javascript的人,并且受制于编写浏览器的人的想法。



正确的方法使缓存无效,以及服务器端验证,如果会话尝试重新发送数据,则会话不再有效。为此,请查看解决方案1 ​​ [ ^ ] Tadit给出的答案。





已添加代码块。



您可以将此javascript添加到登录页面。


No, you cannot disable back button of browser in any conditions. You need to rethink your application logic so that it doesn't matter if the user presses the back button. Don't try and mess with the browser. It's either going to only work sporadically, and then, only for those with javascript enabled, and is subject to the whims of those who write the browsers.

The correct method is invalidate the cache, along with server side validation that the session is no longer valid if they try to resend data. To do this, please check Solution 1[^] answer given by Tadit.


Added code block.

You can add this javascript to login page.

<script type="text/javascript" language="javascript">
    function fnBackButton() {
        window.history.forward()
    }
    fnBackButton();
    window.onload = fnBackButton;
    window.onpageshow = function (evt) { if (evt.persisted) fnBackButton() }
    window.onunload = function () { void (0) }
</script>



有时,客户端浏览器中不会启用javascript。所以我建议你使用c#清除登录页面中的缓存。使用 Page_Init 甚至。


Sometimes, javascript will not be enabled in client browser's. So I would suggest you to clear the cache in login page using c#. Use Page_Init even.

protected void Page_Init(object sender, EventArgs e)
{
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
    Response.Cache.SetNoStore();
}







- Amit


这篇关于注销按钮代码...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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