Click here to Skip to main content
13,351,050 members (55,076 online)
Click here to Skip to main content
Add your own
alternative version


47 bookmarked
Posted 5 Aug 2005

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

, 12 Aug 2005
Rate this:
Please Sign up or sign in to vote.
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
<!-- HTML for article "Disabling browser's back functionality on sign out from Asp.Net" by Rohit123dighe,Rohit123dighe,Rohit123dighe,Rohit123dighe URL: Article content copyright Rohit123dighe,Rohit123dighe,Rohit123dighe,Rohit123dighe All formatting, additions and alterations Copyright © CodeProject, 1999-2005 --><!----------------------------- Ignore -----------------------------><!----------------------------- Ignore -----------------------------><!----------------------------- Article Starts ----------------------------->


                      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.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>

    As there was important data displayed on page it is security threat.<o:p>

It is a threat for web applications displaying important information like credit card numbers  or bank account details.<o:p>


  I tried to find the solution on net but could not get satisfactory answer.<o:p>

On searching i found following problem, and i think it is important to share this issue- <o:p>



What happens when Back Button clicked

When we visit a page it is stored in a cache i.e. history on a local machine. <o:p>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.<o:p>


Caching of Web Pages can happen in three separate entities in a Web environment.<o:p>

  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.<o:p>
  2.  But caching can also occur within the Internet Information Server (IIS) Server, and<o:p>
  3. If a proxy server is present, it can be configured to cache the pages.<o:p>


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.<o:p>

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.<o:p>


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.<o:p>


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

Code in Detail-<o:p>   <o:p>


<o:p> 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.<o:p>



Response.Expires = -1500;      <o:p>

<o:p> 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.<o:p>



Response.CacheControl = "no-cache";<o:p>

<o:p> It tells the browser not to cache the page.<o:p>


Things can work with only one line of code<o:p>

i.e.     Response.CacheControl = "no-cache";<o:p>


But it is good practice to delete the existing page from cache.<o:p>


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.<o:p>


Disabling cache can also be done by adding following line in <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place>Meta section of page<o:p>




But when I tried this it does not worked for me.<o:p> <o:p>

 Proxy Server Caching-<o:p> 

Response.CacheControl = "private";<o:p>

           It disables the proxy server caching and page is cached on local machine.<o:p>

Response.CacheControl = "public";<o:p>

           Proxy server cache is enabled.<o:p>

Users request pages from a local server instead of direct from the source.<o:p>



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


Hence for such applications keeping pages non caching is good solution.<o:p>




<!----------------------------- Article Ends ----------------------------->


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

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

Working on Asp.Net and C# from 2 years

You may also be interested in...


Comments and Discussions

Generalthank u so much buddy Pin
suganthr25-May-11 22:23
membersuganthr25-May-11 22:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 12 Aug 2005
Article Copyright 2005 by RohitDighe
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid