如果页面上有异常

如果页面上有异常

本文介绍了如果页面上有异常,则使输出缓存无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中一个页面中启用了输出缓存,如下所示:

I have output caching enabled in one of the pages as follows:

<%@ OutputCache Duration="300" VaryByParam="*"%>

问题是有时会出现异常,我们会显示相应的消息.但是这个页面随后被缓存,其他用户也看到了异常消息.例如,假设数据库超时,因此抛出 Sql 异常.捕获此异常并显示消息连接到数据库时出错.请稍后再试".现在这条消息被缓存并显示给其他用户,甚至无需查询数据库.

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?

这适用于 ASP.NET 3.5 Webforms.

This is for ASP.NET 3.5 Webforms.

推荐答案

您应该能够移除缓存项

HttpResponse.RemoveOutputCacheItem("/MyPage/MyParameter");

这篇关于如果页面上有异常,则使输出缓存无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 08:50