Click here to Skip to main content
6,822,123 members and growing! (16,614 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

Disabling browser's back functionality on sign out from Asp.Net

By RohitDighe

After sign out from site if browsers back button is clicked it shows the previous page, though user is sign out from the site, to avoid this disabling of cache is done
C#, VB, Windows, .NET, ASP.NET, Visual-Studio, Dev
Posted:5 Aug 2005
Updated:12 Aug 2005
Views:93,846
Bookmarked:31 times
Unedited contribution
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
28 votes for this article.
Popularity: 3.65 Rating: 2.52 out of 5
9 votes, 32.1%
1
2 votes, 7.1%
2
2 votes, 7.1%
3
6 votes, 21.4%
4
9 votes, 32.1%
5

Introduction

                      Disabling the Back Button

 When i was doing coding for sign in and sign out for my clients application, i found that after signing out from the application i transfered the control to login page e.g. login.aspx. At this point if i click the Back button of Browser it shows the content of previous page user was viewing.

    As there was important data displayed on page it is security threat.

It is a threat for web applications displaying important information like credit card numbers  or bank account details.

 

  I tried to find the solution on net but could not get satisfactory answer.

On searching i found following problem, and i think it is important to share this issue-

What happens when Back Button clicked

When we visit a page it is stored in a cache i.e. history on a local machine. Whenever user clicks the Back button, previous page is taken from this cache and displayed; request does not go to the server to check the login information as page is found on local cache. If we submit the page or refresh the page then only page is sent to the server side.

Caching-

Caching of Web Pages can happen in three separate entities in a Web environment.

  1. When you think about caching, you usually think about the Web pages cached locally in your temporary Internet files of the profile that was used to log into local machine as a result of having visited the page.
  2.  But caching can also occur within the Internet Information Server (IIS) Server, and
  3. If a proxy server is present, it can be configured to cache the pages.

Solution-

To avoid the displaying of page on click of back button we have to remove it from cache, or have to tell the server not to cache this page.

So if we do not cache the page then on click of back button request goes to server side and validation can be done whether session exist's or not.

 

This can be achieved by adding following code in the page load of the page for which we do not want to cache the page in history.

 

Response.Buffer=<SPAN style="COLOR: blue">true;<o:p></o:p>
Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
Response.Expires =-1500;
Response.CacheControl = "no-cache";
 if(Session["SessionId"] == null)
    {
	Response.Redirect ("WdetLogin.aspx");
    }
}

Code in Detail-   

Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);

 In this instead of giving the current date we gave the date in the past so it confirms the expiration of page. So that allowing for time differences, rather than specify a static date. If your page is being viewed by a browser in a very different time-zone.

 

 

Response.Expires = -1500;     

 Some IIS internals experts revealed this can be a very touchy parameter to rely upon and usually requires a rather"large" negative number or pedantically, that would be a very small number.

 

 

Response.CacheControl = "no-cache";

 It tells the browser not to cache the page.

 

Things can work with only one line of code

i.e.     Response.CacheControl = "no-cache";

 

But it is good practice to delete the existing page from cache.

 

This code will tell the server not to cache this page, due to this when user clicks the Back button browser will not find the page in cache and then will go to server side to get the page.

 

Disabling cache can also be done by adding following line in Meta section of page

 

<METAHTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

 

But when I tried this it does not worked for me. 

 Proxy Server Caching- 

Response.CacheControl = "private";

           It disables the proxy server caching and page is cached on local machine.

Response.CacheControl = "public";

           Proxy server cache is enabled.

Users request pages from a local server instead of direct from the source.

 

 

So if the information displayed is critical information extra care should be taken to remove the page from cache on sign out.

 

Hence for such applications keeping pages non caching is good solution.

 

 

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

RohitDighe


Member
Rohit Dighe
B.E. Computer from University of Pune, India.

Working on Asp.Net and C# from 2 years
Occupation: Web Developer
Location: India India

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
GeneralMy vote of 1 PinmemberHemant02621:54 14 Nov '09  
GeneralMy vote of 2 PinmemberMember 299258220:23 3 Nov '09  
GeneralThis is a good and usefull article... Thanks.. PinmemberPajosh8321:44 16 Jul '09  
QuestionSession Variables and Back Functionality after Logout......... Pinmembervijay.victory4:22 15 Apr '09  
GeneralNot working in Mozilla sometime Pinmember.NET- India23:12 3 Mar '08  
Questionthank you Pinmembersnopbear3:45 9 Feb '08  
Generaldoesnt work twith mozilla Pinmemberdurbich6:04 11 Sep '07  
GeneralWhat at the End Pinmemberhsr21074:52 29 Jul '06  
QuestionOpera? PinmemberTomazZ0:04 18 Jul '06  
GeneralCan be original. Pinmemberhellomeandme6:38 14 Jun '06  
GeneralRe: Can be original. Pinmemberhspc1:01 17 May '07  
GeneralRe: Can be original. Pinmemberkuyak200018:50 8 Jul '07  
GeneralGood for Beginner Re:Disabling browser's back functionality on sign out from Asp.Net Pinmemberjeya19811:18 29 May '06  
GeneralRe:Disabling browser's back functionality on sign out from Asp.Net Pinmemberwinheart22:39 21 Feb '06  
GeneralRe:Disabling browser's back functionality on sign out from Asp.Net PinmemberAftab Naveed4:05 19 Jul '06  
GeneralDisabling caching on the back button Pinmemberdb..2:05 12 Aug '05  
GeneralRe: Disabling caching on the back button Pinmemberweblech1:41 19 Nov '08  
GeneralBack Button won't come from Server! PinmemberJJF0076:00 5 Aug '05  
GeneralRe: Back Button won't come from Server! Pinmemberdarisole7:18 5 Aug '05  
GeneralRe: Back Button won't come from Server! PinmemberRohit123dighe20:57 7 Aug '05  
GeneralRe: Back Button won't come from Server! Pinmemberdarisole22:33 7 Aug '05  
GeneralRe: Back Button won't come from Server! [modified] Pinmemberl.karimi.j3:13 17 Oct '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

PermaLink | Privacy | Terms of Use
Last Updated: 12 Aug 2005
Editor:
Copyright 2005 by RohitDighe
Everything else Copyright © CodeProject, 1999-2010
Web18 | Advertise on the Code Project