Disable Browser Caching (ASP.NET)

Category:
C#, VB.NET, ASP.NET
Type:
Snippets
Difficulty:
Beginning
Author:
Intelligent Solutions Inc.

Version Compatibility: ASP.NET

More information:
This one line, at the top of your aspx page or in your page_load event handler, prevents the web page from being saved in the client cache, exactly what the snippet at http://www.freevbcode.com/ShowCode.Asp?ID=243 does for ASP. As a demo, try putting this code into your page, with and with disabling the cache, navigating to a new page, then back to the original page:

response.write(DateTime.Now.ToString)

Without the cache disabling code, the date/time won't change. With the code, you will see it change when you click the back button.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: