使用c#禁用asp.net中的后退按钮 [英] disable back button in asp.net using c#

查看:151
本文介绍了使用c#禁用asp.net中的后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用菜单栏中的后退按钮,这样用户就不会转到上一页



我一直在寻找解决方案。



我找到了很多建议,但似乎没有一个适合我。



防止用户进场到上一页<我有,在我的aspx页面上

I want to disable back button in the menu bar so that a user does not go to the previous page

I have been searchiong net for a solution.

I have found many suggestions but none seems to work for me.

To prevent a user from goin to previous page< I have, on my aspx page

<head  runat="server">    
<title><title>
<script type="text/javascript">
        function DisableBackButton() 
        {
            window.history.forward()
        }
        DisableBackButton();
        window.onload = DisableBackButton;
        window.onpageshow = function (evt) { if (evt.persisted) DisableBackButton() }
        window.onunload = function () { void (0) }
 <script>
</head>
<body  önunload="disableBackButton()">
 //code for page from where i dont want users to use back button
</body>



在我的aspx.cs页面中我有代码


In my aspx.cs page i have the code behind

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

        Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1d);
        Response.Expires = -1500;
        Response.CacheControl = "no-cache";
        Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);

    }



它没有用。后退按钮仍然将它带到上一页。



我也试过


It has not worked. the back button still takes it to previous page.

I have also tried

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



我也试过上面的代码


I have also tried with the above code

protected override void OnPreRender(EventArgs e)
{
        string strDisAbleBackButton = "";
  ClientScript.RegisterClientScriptBlock(this.GetTyp(), "clientScript",strDisAbleBackButton);

}



但似乎什么都不行



最后我写了一个用户不应该使用后退按钮的警告消息,但是用户似乎忽略了此消息并且因为两个页面具有不同的角色而导致问题,并且当用户从第一个apge转到第二个apg并且在使用时,用户的角色会动态变为cahnged由于角色不同,用户不被接受。



Kinldy帮助我



非常感谢为你的帮助


But nothing seems to work

Finally i have written a warning message for users that they should not use the back button but users seem to ignore this message and get into problem because the two pages have different roles and role of user is dynamically cahnged when the user goes from first apge to second one and on use of back button the user is not accepted because of different role.

Kinldy help me

Many thanks for your help

推荐答案

你也可以试试这个:

You can also try this:
<META Http-Equiv="Cache-Control" Content="no-cache"/>
<META Http-Equiv="Pragma" Content="no-cache"/>
<META Http-Equiv="Expires" Content="0"/>



来源:注销后浏览器后退按钮问题 [ ^ ]


前进窗口 [ ^ ]

操纵浏览器历史记录 [ ^ ]

禁用浏览器后退按钮,您不应该或者说不能。检查我提供的链接。这些仅仅是浏览器历史记录,让您感觉后退按钮被禁用但不完全。

Window.History.Forward()是一个简单的。这会阻止用户返回上一页。第二个链接可以帮助您找到更多操作方法。

希望这会有所帮助。

回复您的查询(如果有的话)。

谢谢。

:)
Window Forward[^]
Manipulating Browser History[^]
Disabling browser back button, you should not or say you cannot. Check the links I have provided. These just maipulate with the browsers history letting you feel the Back button is disabled but not exactly.
Window.History.Forward() is a simple one. Which prevents the user going back to previous page. The second link helps you find more methods to manipulate on this.
Hope this helps.
Post back your queries if any.
Thanks.
:)


http://www.aspdotnet-suresh.com/2011/11/disable-browser-back-button.html [ ^ ]





试试这个......
http://www.aspdotnet-suresh.com/2011/11/disable-browser-back-button.html[^]


try this...


这篇关于使用c#禁用asp.net中的后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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