【问题标题】:Disable caching in Fire Fox in ASP.NET and C#在 ASP.NET 和 C# 中禁用 Firefox 中的缓存
【发布时间】:2011-09-10 12:19:52
【问题描述】:

我开发了一个处理信用卡付款的网络应用程序,当用户在收到付款确认页面后点击 Fire Fox 中的后退按钮时,它会发布重复付款。

我在付款表单和确认页面中都输入了以下代码,但它仍然发布重复付款:

Response.Cache.SetExpires(DateTime.UtcNow.AddYears(-1));
Response.Cache.SetValidUntilExpires(false);
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
Response.Cache.SetAllowResponseInBrowserHistory(false);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

我做错了什么,我该如何解决?

【问题讨论】:

标签: c# asp.net firefox caching


【解决方案1】:

rerun 在 cmets 中有一个好处。关于这个问题,试试这个代码(source):

   Response.ClearHeaders();
   Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
   Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
   Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
   Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
   Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1 
   Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1 
   Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1 
   Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1 
   Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1 
   Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1 

它应该强制所有浏览器获取最新版本,而不是页面的缓存版本。 (可能想要更改 Expires 的数据,因为该帖子来自 2006)。

【讨论】:

    【解决方案2】:

    对于不执行重复处理的更一般性问题,请阅读Not allow resubmit of page 提供的建议。

    总而言之,有几种方法可以尝试阻止客户端的浏览器重复请求,但最终,如果提交永远不会被处理两次是绝对重要的,那么您需要在服务器端检查付款是否已经被处理。在他们提交的表单中添加一个唯一标识符,将其记录在数据库中,如果您再次看到相同的标识符,不要处理请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多