Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello guys,
I am using following script in my page
XML
<script>
           $(document).ready(function () {
               debugger;
               var checkId = document.getElementById("RedirectWindow");
               if (checkId != undefined) {
                   setInterval(function () {
                       window.location.href = "@Url.Action("Index", "Dashboard")";
                   }, 2000);
               }
           });
      </script>


Below is condition to render div
XML
@{
         if(ViewBag.SuccessMessage!=null)
           {
            <div id="removeDiv">
                <div style="color: green" id="RedirectWindow">
                   <label>Profile updated successfully...</label>
            </div>
                 </div>
            }
    }


now i am doing here first time i am passing some value in viewbag based condition i render success message to end user and after waiting for 2 seconds user redirected to another page
That page name is Profile and redirected page is dashboard now from dashboard if user clicks for profile link it goes back to this page and condtional div does not reneder.
All goes fine till here!!!

If i clicks on browser back button it goes to profile page there it checks if div is there it founds it there and gets redirected to dashboard page again
I want if user goes back by clicking on browser back button instead of taking page from cache.
Posted

You just disable the cache.

To disable cache you can use
HTML
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />


Or from code behind
C#
Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
Response.AppendHeader("Expires", "0"); // Proxies.
 
Share this answer
 
Comments
C For Code!!! 12-Dec-13 0:18am    
Ya you are correct but for me its not working why becuase i dont know may be i am using it in MVC it show exception as not recognised...

Still thanks for answering and effforts....
Hello guys concept still here is same as described by ASHOK .
Below code when i put it in code behind it works for.

VB
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()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900