繁体   English   中英

登录C#asp.net后禁用Web浏览器后退按钮

[英]Disable web browser back button after login in c# asp.net

用户登录后如何无法返回上一个未登录页面? 有可能这样做吗?

在C#中尝试

public void disablebrowserbackbutton()
{
 HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
 HttpContext.Current.Response.Cache.SetNoServerCaching();
 HttpContext.Current.Response.Cache.SetNoStore();
}

客户端

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

登录后,将用户的详细信息保留在会话中...在登录页面的pageLoad事件中,检查该会话是否具有任何值,如果有任何值,则将页面重定向到“主页”或“索引”页面,或在登录后要加载的任何内容。

在登录页面的页面中加载:

  string userID= (string)(Session["userID"]);
    if(userID!=NULL)
     {
      // code to redirect to home page
     }

if(!IsPostBack){if(Session [“ LoginId”] == null)Response.Redirect(“ frmLogin.aspx”); 否则{Response.ClearHeaders(); Response.AddHeader(“ Cache-Control”,“ no-cache,no-store,max-age = 0,必须重新验证”); Response.AddHeader(“ Pragma”,“ no-cache”); }}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM