0

我正在使用 ASP.NET 和 C#。单击注销后,我正在使用它。

Session.Abandon();
Session.RemoveAll();
Page.Responce.Cache.setCacheability(HttpCacheability.NoCache);
Response.Redirect("Default.aspx");

但在此之后,如果他们点击浏览器中的后退按钮,它将转到上一页。

有什么办法可以防止这种情况发生吗?

谢谢..

编辑:

我确实用过这个。

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        if (Session["LoginId"] == null)
            Response.Redirect("frmLogin.aspx");
        else
        {
            Response.ClearHeaders();
            Response.AddHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
            Response.AddHeader("Pragma", "no-cache");
        }
    }
}

因此,他们单击浏览器后退按钮,然后将调用页面加载,因此我们可以检查会话变量以进行身份​​验证。

4

4 回答 4

2

我正在发布一个链接我希望这个链接可以指导你并帮助你任何你需要的点击这里

http://www.dotnetfunda.com/

于 2012-09-22T10:42:23.013 回答
1

protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) {

            if (Session["Navigation"] == null)
            {
                Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.Cache.SetNoStore();
                Response.Redirect("~/Login.aspx");
            }                                                                               protected void lnkbtnLogOut_Click(object sender, EventArgs e)
    {

        Session["Navigation"] = null;
        Session.Abandon();

        Response.Redirect("~/Login.aspx");
    }                                                                                             but it's not working.It still redirects to prevoios page after click on back button
于 2013-01-18T07:33:29.790 回答
0

设置页面属性<outputcache=none>

于 2012-09-22T10:00:51.123 回答
0

以下将为您服务:

该代码禁用浏览器中的缓存。

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();

或者

注销后,您可以添加脚本以删除浏览器上的历史记录。

Page.ClientScript.RegisterStartupScript(this.GetType(),"cle","windows.history.clear",true);

希望以上两个中的任何一个都可以。


您可以检查Session["---"]变量可用性,如果会话不可用,则将用户重定向到登录/注册页面。

我的意思是,您正在放弃会话,这可能会破坏会话变量。所以当用户点击后退按钮时,系统会检查会话,它不会发现并且用户将被重定向到登录/注册页面。

如果您使用内置的成员资格类进行用户管理,那么用户 [Authorize] 属性。这可能会阻止用户在注销后访问页面,并将未注册的用户重定向到登录/注册页面。

于 2012-09-22T10:08:34.123 回答