简体   繁体   English

asp.net中注销后返回历史不清晰的问题

[英]problem of back history not being clear after logout in asp.net

protected void Page_Load(object sender, EventArgs e){
    Session.Abandon();
    FormsAuthentication.SignOut();

    Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Redirect("~/Admin/adminLogin.aspx");

}

I m not using any master page.so i have make one logout page and write code in it as above.我没有使用任何母版页。所以我制作了一个注销页面并如上所述在其中编写代码。 But after logout it still goes back to previous page.但是注销后它仍然会回到上一页。

You can put this code in the page load您可以将此代码放在页面加载中

protected void Page_Load(object sender, EventArgs e)
{
    if (!HttpContext.Current.User.Identity.IsAuthenticated)
    {
        Response.Redirect("Login.aspx");
    }
}

I'm not sure this is the answer you are looking for exactly.我不确定这是否是您正在寻找的答案。 What I do is I put the authentication code in a custom HTTPModule, that way it is executed before all page requests and you simply check status and do your redirection from there.我所做的是将身份验证代码放在自定义 HTTPModule 中,这样它会在所有页面请求之前执行,您只需检查状态并从那里进行重定向。

Then you simply put an exception for your login pages and resource locations.然后,您只需为您的登录页面和资源位置设置一个例外。 This has the advantage of being able to secure all files on the server with the right settings.这样做的好处是能够使用正确的设置保护服务器上的所有文件。

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

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