簡體   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