[英]How to deny access after logout by means of back button or url typed in browser in asp.net?
我甚至在注銷后仍面臨訪問頁面的問題。.我訪問了許多表格,但大多數人說禁用后退按鈕。.我想通過代碼而不是禁用后退按鈕來實現。
我的問題 :
注銷后,我可以通過“后退”按鈕訪問上一頁,注銷后可以鍵入URL,例如“ localhost / admin.aspx”。
請幫助我避免上述兩個問題? 我正在使用C#..! 提前謝謝了..
嘗試這個
protected void LoginStatus1_LoggedOut(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Roles.DeleteCookie();
Session.Clear();
}
您的頁面被瀏覽器緩存,這有助於提高頁面加載的性能。 可以禁用輸出緩存。 您可以在http://forums.asp.net/t/1268449.aspx上找到一些注意事項。
如果是手動會話管理,請在僅登錄后才能使用的頁面上檢查會話。 在其PageLoad事件上使用類似以下的內容
if(Session [“ SomeVar”] == null){
// redirect to login page or somewhere else }
如果您使用的是Membership Provider,那么我認為它將自動為您服務。
您也可以設置Cache Expiration Policy以避免后退按鈕。以下是相同代碼
private void DisableClientCaching()
{
// Do any of these result in META tags e.g. <META HTTP-EQUIV="Expire" CONTENT="-1">
// HTTP Headers or both?
// Does this only work for IE?
Response.Cache.SetCacheability(HttpCacheability.NoCache);
// Is this required for FireFox? Would be good to do this without magic strings.
// Won't it overwrite the previous setting
Response.Headers.Add("Cache-Control", "no-cache, no-store");
// Why is it necessary to explicitly call SetExpires. Presume it is still better than calling
// Response.Headers.Add( directly
Response.Cache.SetExpires(DateTime.UtcNow.AddYears(-1));
}
嘗試使用以上
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
Response.AddHeader("Pragma", "no-cache");
Response.Expires = 0;
在登錄按鈕上的登錄表單中,單擊
Session["ABC"] = UserNameTextBox.Text; Session["Username"] = UserNameTextBox.Text;
在每個頁面上加載除login.aspx以外的事件
string a = Convert.ToString(Session["ABC"]); if (a == "") { Response.Redirect("Login.aspx"); }
注銷時清除會話。 Session.Abandon()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.