How to prevent user to visit last visited page ?

As a developer some times we may have to prevent users to visit back to the previously visited page  . let us see the easy way to achieve this , I know that still many of us having the doubt “How to prevent visitor to click back button?” or “How to prevent user to visit last visited page ?”.

In the page’s code-declaration block, or in the code-behind class for the page, include code that sets the expiration policy for the page by using Response.Cache syntax. The following example sets expiration for the page as the @ OutputCache directive does in the previous procedure.
                              Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
                              Response.Cache.SetCacheability(HttpCacheability.NoCache);

If  we want to store the information in cache for a particular period time , then we can use the below given code.This code will help us to keep the data in Cache for a particular period of time.Once we set expiration for a page programmatically, we must set the Cache-Control header for the cached page as well. Use the HttpCachePolicy.SetCacheability method to set the HttpCacheability enumeration to Public.

                           Response.Cache.SetExpires(DateTime.Now.AddSeconds(600));
                           Response.Cache.SetCacheability(HttpCacheability.Public);
                           Response.Cache.SetValidUntilExpires(true);

 

thanks !

 

Leave a Reply

Your email address will not be published. Required fields are marked *