繁体   English   中英

在注销后如何通过在asp.net中的浏览器中键入后退按钮或URL拒绝访问?

[英]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上找到一些注意事项。

  1. 使用javascript代码禁用后退按钮。
  2. 如果是手动会话管理,请在仅登录后才能使用的页面上检查会话。 在其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;
  1. 在登录按钮上的登录表单中,单击

     Session["ABC"] = UserNameTextBox.Text; Session["Username"] = UserNameTextBox.Text; 
  2. 在每个页面上加载除login.aspx以外的事件

     string a = Convert.ToString(Session["ABC"]); if (a == "") { Response.Redirect("Login.aspx"); } 

注销时清除会话。 Session.Abandon()

暂无
暂无

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

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