How to solve back button problem after logout


Are you searching logout problem solving based article? We can use this article for guideline on How to solve back button problem after logout. I also provides code snippet for back button problems after logout .

Description



We sometime face problem of back button that after logout then if we click back button then we able access those pages those already visited and that page always require login Session so if click on button go to login page.

Hereunder will give the code even if you click back button after logout you will remain in same page after you click back button.

If you click logout button go to login page and then click back button you will be same login page if you use this code.Use this code onclick of logout button.


Session.clear();//clear session
Session.Abandon();//Abandon session
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Redirect("Logout.aspx");


Article by Abhay Kumar Raut
DNS MVM and .Net Guru Team Lead at CirrusCloud Systems Bhubaneswar,Odisha Thanks and Regards, Abhay Kumar Raut

Follow Abhay Kumar Raut or read 39 articles authored by Abhay Kumar Raut

Comments

Guest Author: Vijay14 Jun 2012

this code is not working fully

Guest Author: wajid16 Feb 2013

not work properly. problem still remain...

Author: Abhay Kumar Raut22 Feb 2013 Member Level: Gold   Points : 3

I am unable to edit the code.Please use this code in Page_Init event..If your are using master page in then put this in master.aspx.cs file.

protected void Page_Init(object sender, EventArgs e)
{

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.Cache.SetNoStore();

}

Guest Author: Balaji24 Mar 2013

Yes, Abhay Kumar Raut's post fix the issue. But the catch is, if the "Back" button is clicked, previous page URL is shown rather than "Log out" page URL.

Author: Jivani10 Apr 2013 Member Level: Gold   Points : 0

you can check session varibale valu in master page

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Convert.ToString(Session["Username"]) != "")
{ }
else
{
Response.Redirect("admin_login.aspx");
}
}
}

Author: Laxmikant11 Apr 2013 Member Level: Gold   Points : 4

Nice article...

One trick is here

1. Create one interstitial page say "LogOutInter.aspx"
2. write the logout code which is suggested in this article on logout button or link (not in interstitial page) and redirect to LogOutInter.aspx.
3. in LogOutInter.aspx load event check the urlreferrer if it is coming from the logoff button redirect to your home page or default page. else if it is coming from other pages redirect to same page which you got from urlreferrer.

So when you click to logoff you go to LogOutInter.aspx and from there some other page. When user clicks back button while is on some other page we will redirect to LogOutInter.aspx and from there again to some other page.

Guest Author: Jannika28 May 2013

It's always a pleasure to hear from someone with expertise.

Author: Prabhukumar J02 Jun 2013 Member Level: Silver   Points : 0

Check this below link.

http://www.dotnetgallery.com/lab/resource47-Avoid-back-button-after-logout-in-aspnet-application.aspx



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: