开发者

Forms authentication - logging out and page history

开发者 https://www.devze.com 2023-03-28 17:28 出处:网络
In my ASP.NET site, when a user clicks logout, I call FormsAuthentication.SignOut and Session.Abandon and redirect them to the login page. This works fine.

In my ASP.NET site, when a user clicks logout, I call FormsAuthentication.SignOut and Session.Abandon and redirect them to the login page. This works fine.

However, when I click "back" in the browser I can still开发者_Python百科 see the last page viewed before logout was clicked. When I click on anything I am returned to the logon page as expected.

Is there anyway to expire the page that logout was clicked on so that users never see it when they click back?


Prevent credential and content caching:

First, ensure the forms cookie is not being created sticky:

FormsAuthentication.SetAuthCookie(userName, false);

Next, a little something in the Global.asax to prevent page requests from caching:

public override void Init()
{
    base.Init();

    BeginRequest += new EventHandler(OnBeginRequest);
}

void OnBeginRequest(object sender, EventArgs e)
{
    if (!(Request.Path.EndsWith("Resource.axd")))
    {
        Response.Cache.SetExpires(DateTime.UtcNow.AddSeconds(-1));
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoStore();
    }
}

The combination of the above two approaches has fixed a similar issue in a few apps I've worked on. We intentionally allowed .axd file caching to keep performance impact as minimal as possible - we have heavy use of third party controls that generate axd requests in the background.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号