退出后不允许用户返回 [英] Do not allow user to go back after logout
本文介绍了退出后不允许用户返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在主页上,当我单击注销时,它会转到登录页面按钮.但是,当我单击浏览器的后退按钮时,它将直接转到主页.如何在ASP.NET和C#.net中处理此类错误?
我们需要在Global.asax中编写任何代码吗?
In homepage when I click on logout its goes to login page button. But when I clicked back button of the browser it directly go to Home page. How to handle this type of error in asp.net, C#.net?
Do we need to write any code in Global.asax?
Someone please help me.
推荐答案
window.history.forward(1);
document.attachEvent(&"onkeydown&",my_onkeydown_handler);
函数my_onkeydown_handler()
{
开关(event.keyCode)
{
案例116://F5;
event.returnValue = false;
event.keyCode = 0;
window.status =我们已禁用F5";
休息;
}
}
window.history.forward(1);
document.attachEvent("onkeydown", my_onkeydown_handler);
function my_onkeydown_handler()
{
switch (event.keyCode)
{
case 116 : // F5;
event.returnValue = false;
event.keyCode = 0;
window.status = "We have disabled F5";
break;
}
}
If you are using forms authentication.
// Page load event of Logout.aspx
FormsAuthentication.SignOut();
Response.Redirect("Default.aspx");
//Session
//in your Global.asax file
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
if (Session["UserID"] == null)
{
Response.Redirect("Login.aspx");
}
no need to write any code in Global.asax file....
Use javascript to disable the back button....
<a href="http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911/Disabling-the-Back-Button.htm">http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911/Disabling-the-Back-Button.htm</a>[<a href="http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911/Disabling-the-Back-Button.htm" target="_blank" title="New Window">^</a>]
这篇关于退出后不允许用户返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文