问题描述
我有一个登录页面和主页。用户可以使用一个用户名和密码登录页面主页登录。我想实现的是:
I have a login page and a home page. Users can log in from the login page to the home page using a username and password. What I want to achieve is:
1)当用户在主页上登出,他/她不应该通过点击浏览器中的回或转发的按钮登陆
1) When user log out from home page, he/she should not be "logged in" by clicking the back or forward button in the browser.
2),可以肯定的是,浏览器将存储主页的历史。但是,当在浏览器中可用的主页链接,历史上的用户点击,它应该被重定向到登录页面,而不是主页。
我曾尝试通过在Page_Load事件以下code在主页上清除缓存:
I have tried clearing the cache by using the following code in page_load event in the home page:
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
但它仍然没有工作。任何形式的帮助是非常AP preciated。
But it is still not working. Any kind of help is highly appreciated.
推荐答案
使用follwing code在prerender()事件。它为我工作。
Use follwing code in OnPrerender() event of home page . It worked for me.
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string sb;
sb = "<script language=javascript>\n";
sb += "window.history.forward(1);\n";
sb += "\n</script>";
ClientScript.RegisterClientScriptBlock(Page.GetType(), "clientScript", sb);
}
这篇关于如何清除浏览器的历史OAN清除缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!