[重新发布]当我们单击浏览器的后退按钮时,如何在asp.net中终止会话

[重新发布]当我们单击浏览器的后退按钮时,如何在asp.net中终止会话

问题描述:

我有一个正常的登录页面,一个主页为"ABC.Master",另外三个为

子页面为第1页,第2页,第3页.第1页,第2页,第3页为子

母版页"ABC.Master"的页面.

输入用户名和密码后,如果我单击登录",它将移至页面

1和第1页,如果我单击某些链接,它将移至第2页.从第2页起

如果我单击浏览器后退"按钮,则应返回到第1页,然后如果我

单击第2页或第3页链接,则会话应该过期.


注意:它应该完全像银行网站一样.即在点击浏览器后退

按钮会话必须过期.

重新发布 [此历史记录] [ ^ ]

I have one normal Login page ,1 Master Page as "ABC.Master" and 3

child pages as page 1, page 2, page 3. The page 1,page 2, page 3 are the child

pages of Master Page "ABC.Master".

After entering the Username and Password if I click on Login it moves to the Page

1 and from Page 1 if I click on some links it moves to Page 2. And from Page 2

if I click on the Browser Back button it should go back to Page 1 and then if I

click on Page 2 or Page 3 link then the Session should get expired.


Note: It should be purely like Banking website. i.e) On clicking the Browser back

button the Session has to get expired.

Repost of [This history][^]

将此用于会话清除

use this for session clear

protected void Page_Init(object sender, EventArgs e)
       {
           Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));

           Response.Cache.SetCacheability(HttpCacheability.NoCache);

           Response.Cache.SetNoStore();
       }



之后的页面中使用此


Use this in page after

Session.Abandon();


因为page1,page2和page 3具有相同的母版页.所以在哪里放弃会话(); ?如果我放弃了母版页中的会话,那么它将无法从登录页移动到母版页本身.
As there is a same Master Page for page1,page2 and page 3 . so where to give session abandon () ; ? if i give session abandon in master page then it wont be able to move from login page to Master page itself .


页面加载写入

if(Session ["YourKey"]!= null)
{
Session.Remove("YourKey");
}

希望它能工作
on page load write

if(Session["YourKey"]!=null)
{
Session.Remove("YourKey");
}

hope it will work