简体   繁体   English

在特定页面上禁用页面缓存

[英]Disable page cache on a specific page

Not sure if I really am on the right forum, but if not, just tell me. 不知道我是否真的在正确的论坛上,但是如果不正确,请告诉我。 I have a page that is coded in ASP (not .net) which is used to send email. 我有一个用ASP(不是.net)编码的页面,用于发送电子邮件。 We are currently having a problem in which the page seem to be sent twice sometime. 我们目前遇到一个问题,该页面似乎有时会发送两次。 Upon checking, we found out that those who have this problem are coming from big organisation, so it was suggested that their server might cache the file for some reason. 经过检查,我们发现有此问题的人来自大型组织,因此建议他们的服务器出于某种原因可能会缓存文件。

I would like to know, is there a way in HTML (or ASP ) to prevent that from happening ? 我想知道,HTML(或ASP)中是否有一种方法可以防止这种情况的发生? Or is it in IIS that we must set this up ? 还是必须在IIS中进行设置?

EDIT : I forgot to mention is that sometime, the time between the two mails can be in hours, not mere seconds 编辑:我忘了提到的是,有时候,两封邮件之间的时间可以是几小时,而不仅仅是几秒钟

Thanks, 谢谢,

I don't see any cache problem here. 我在这里看不到任何缓存问题。

The only solution i see is to store somewhere server side(db, file system) the list of emails sent and check the list before send them. 我看到的唯一解决方案是将发送的电子邮件列表存储在服务器端(数据库,文件系统)的某个位置,并在发送之前检查该列表。

With this approach, you will be sure to send just one mail to the specified address avoiding double submit or other possible problem. 使用这种方法,您将确保只向指定地址发送一封邮件,以避免重复提交或其他可能的问题。

I do not see how this could have anything to do with caching. 我不知道这与缓存有什么关系。 After all, a cached page contains the generated html, and thus it would not trigger another execution of the code that sends the email. 毕竟,缓存的页面包含生成的html,因此不会触发发送电子邮件的代码的另一次执行。

However, my best guess is that it has to do with users that refresh the page. 但是,我最好的猜测是,它与刷新页面的用户有关。 To avoid this, you could implement the post/redirect pattern, where after sending the mail you redirect to another page (or the same page but with different form parameters). 为避免这种情况,您可以实现发布/重定向模式,在该模式下,发送邮件后,您将重定向到另一个页面(或同一页面,但具有不同的表单参数)。 This way the user can refresh the page as many times as he/she wants without triggering another email being sent. 这样,用户可以在不触发另一封电子邮件的情况下,根据需要多次刷新页面。

If your problem is caching, there's really nothing you can do to keep an organization from caching it. 如果您的问题是缓存,那么实际上您无能为力,无法阻止组织缓存它。

You can try to add this code to see if it makes a difference: 您可以尝试添加以下代码以查看它是否有所不同:

Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache" 

If this doesn't work, you may need to contact that organization's IT department and ask them to add a caching exception for your page/site. 如果这不起作用,则您可能需要联系该组织的IT部门,并要求他们为您的页面/站点添加缓存例外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM