I have output caching enabled in one of the pages as follows:
<%@ OutputCache Duration="300" VaryByParam="*"%>
The issue is that sometimes there is an exception and we display an appropriate message. But this page is then Cached and other users are also seeing the exception message. For example, suppose the database times out and thus a Sql Exception is thrown. This exception is caught and a message is displayed "Error connecting to database. Please try after some time". Now this message is cached and shown to other users without even querying the database.
So what I want to do is invalidate the particular output cache if there is an exception, or perhaps not cache when there is an exception. How can this be done?
This is for ASP.NET 3.5 Webforms.