注销后避免显示上一页? [英] Avoid to display previous page after logout?

查看:88
本文介绍了注销后避免显示上一页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我使用web usercontrol为页面创建一致的布局,如下所示,



Hi,

I create a consistent layout for the pages using web usercontrol as below,

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Header.ascx.cs" Inherits="M2iSTS2.UserControl.Header" %>

<link href="/Styles/styles.css" rel="stylesheet" type="text/css" />

 <div id="header" class="header">
  	<h1 class="h1">TrackU: Student and Vehicle Tracking System</h1>
    <p class="p"><a class="a" href="/Account/login.aspx">Logout</a></p>
  </div>
  <div>
  	<ul class="ul">
    	<li class="li"><a class="lia" href="/Admin/Fleet.aspx">Fleet</a></li>
        <li class="li"><a class="lia" href="/Admin/StudentInfo.aspx">Student Info</a></li>        
        <li class="li"><a class="lia" href="/Admin/RouteSettings.aspx">Route Settings</a></li>        
        <li class="li"><a class="lia" href="/Admin/Reports.aspx">Reports</a></li>        
    </ul>
  </div>





当我点击每个页面中的注销链接时,它会重定向到login.aspx.Then,

当我点击浏览器中的后退按钮时它会返回上一页,不要登录页面。



当在表单标签中使用logout作为服务器控件时,

无法在服务器表单中添加另一个表单。







怎么避免这个?



谢谢



when i click logout link in each page, it redirect to login.aspx.Then,
when i click back button in browser it go back to previous page, not to login page.

when use the logout as server control inside a form tag,
cant add another form inside the server-form.



how to avoid this?

Thanks

推荐答案

我想你的LogOut按钮事件,你需要清除会话



I think on your "LogOut" button event, you need to clear session that is

Session.Clear();
Session.Abandon();
Response.Redirect("logout.html");





一旦你点击这个按钮,你的会话就不见了。

现在在公共控件的页面加载上添加代码来检查会话是否是活动或消失如下





Once you click this button you session is gone.
Now add code on the pageload of the common control to check if the session is active or gone as below

if(Session["username"] == null)
{
Response.Redirect("login.aspx");
}





这是处理注销的最常用方式。它应该服务于你的目的,除非我误解了你的要求。



Hoep有帮助。如果是,请标记为答案/ upvote。

Milind



This is the most general way logout is handled. And it should serve your purpose unless I have misunderstood your requirement.

Hoep that helps. If it does, mark as answer/upvote.
Milind


1)在仅供经过身份验证的用户使用的所有页面上,包括:

< %@ OutputCache Duration =1NoStore =trueLocation =None%>



2)在每个安全页面的PageLoad事件中,检查:

if(Session [loggedInUser] == null)

Response.Redirect(Logout.aspx);



3)点击退出按钮,清除Session.Abandon(); Session.Clear();然后将用户重定向到PreLogout.aspx页面。



4)将此javascript包含在PreLogout.aspx页面的body标签中:

< ;bodyönload=top.location.href =''Logout.aspx'';>< / body>
1) On all the pages that are only available to authenticated users, include:
< %@ OutputCache Duration = "1" NoStore="true" Location="None" % >

2) On PageLoad event of every secured page, check:
if(Session["loggedInUser"] == null)
Response.Redirect("Logout.aspx");

3) On click of log out button, clear session with Session.Abandon();Session.Clear(); then redirect the user to PreLogout.aspx page.

4) Include this javascript in the body tag of PreLogout.aspx page:
<body önload="top.location.href = ''Logout.aspx'';"></body>


您需要在浏览器中禁用页面缓存。这可以通过服务器端事件完成,或者如果您想在客户端执行此操作,则需要使用浏览器历史记录的技巧。以下是两种方式



服务器端



You need to disable page caching in the browser. And this can be done via server side event or if you want to do it on client side, you need to use the trick the history of the browser. Here are both the ways

Server side

public static void DisablePageCaching() 
{ 

//Used for disabling page caching 
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false); 
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore(); 

} 





登出页面上的客户端..但请记住在所有浏览器中进行测试,因为所有浏览器可能不支持这个...服务器端选项总是最好的





Client side on your logout page.. But remember to test in all browsers , since all the browsers may not support this ... The server side option is always the best

<script>
window.onload= function  {
    history.go(-1);
}
</script></script>


这篇关于注销后避免显示上一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆