preventing页审查后退出 [英] Preventing Page Review after Logout
问题描述
这是在谷歌一个非常著名的问题。我发现了几个建议,以实现该功能。我已实施的步骤如下所述:
This is a very famous questions in Google. I found several suggestion to achieve this feature. The procedure I have implemented is described below:
我已经在主页上,并点击该链接,我重定向用户到注销页面增加了一个注销链接。
I have added a Logout Link in the home page and on clicking that link I am redirecting user to the logout page.
protected void LinkButton1_Click(object sender, EventArgs e) {
Response.Redirect("../Logout.aspx");
}
现在在Logout.aspx我已经加入:
Now in the Logout.aspx I have added:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
在Page_Load方法code后面。
in the Page_Load method code behind.
此外,我已经添加了一个的asp:ScriptManager的
和 ASP:定时器
到 Logout.aspx
:
Also I have added a asp:ScriptManager
and a asp:Timer
to that Logout.aspx
:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick" >
</asp:Timer>
该Timer1_Tick方法是:
The Timer1_Tick method is:
protected void Timer1_Tick(object sender, EventArgs e) {
FormsAuthentication.SignOut();
Session.Abandon();
FormsAuthentication.RedirectToLoginPage();
}
这是从 Logout.aspx
重定向到的Login.aspx
。此外,我已经添加在下面的JavaScript方法 Logout.aspx
:
This is redirecting to the Login.aspx
from Logout.aspx
. Also I have added the following JavaScript method in the Logout.aspx
:
function disableBackButton() {
window.history.forward(1);
}
disableBackButton();
window.onload = disableBackButton();
window.onpageshow = function (evt) { if (evt.persisted) disableBackButton() }
window.onunload = function () { void (0) }
和它的工作,只有当我单挑单击后退按钮,或者点击多次与暂停。但是,如果被点击它多次连续,然后我又被放置在首页。
And it is working, only if I single click the Back button, or click multiple times with pause. But if it is being clicked multiple times consecutively then I am again being placed in the Home page.
我该如何解决这个问题?
How can I solve this problem?
推荐答案
我用下面的注销,其中i清除饼干,我还没有登录出任何问题,真正的我的用户。
I use the following logout, where i clear the cookies, and i have not had any problems login-out my users "for real".
修改
请注意,浏览器缓存经常在其历史上的页面,我不认为你可以$ P $无法显示的页面,注销后pvent他们!
Note that the browser often cache the pages in its history, and i do not think that you can prevent them from showing the pages, after a logout!
FormsAuthentication.SignOut();
Session.Abandon();
// clear authentication cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
// clear session cookie
HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
cookie2.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie2);
FormsAuthentication.RedirectToLoginPage();
这篇关于preventing页审查后退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!