tags:

views:

47

answers:

3

Hi,

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. 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 ? Or is it in IIS that we must set this up ?

EDIT : I forgot to mention is that sometime, the time between the two mails can be in hours, not mere seconds

Thanks,

+1  A: 

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.

systempuntoout
We checked with out clients and none of them refreshed the page or double-click on the button. I know we can't usually rely on that kinda of input from people, but some of them are superusers so I feel it's reliable. Plus it only happens at some place, not all.
David Brunelle
Yes i saw on your EDIT :).Why downvote??
systempuntoout
Dunno, I'm not the one who did it.
David Brunelle
upvoted. It's a legit answer, no reason for the downvote.
AaronS
I though this could be a good idea to.If we can't solve the problem 'normally' we will rewrite the whole thing and add validation. It's just more a PITA if we have to though.
David Brunelle
A: 

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.

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.

klausbyskov
We checked that possiblitity already and it seems that it is actually impossible to refresh the page because when it is called, the page is runned and redirected to another page. I tried refreshing that other page to see if the email is sent twice but it is not.One thing I forgot to mention is that sometime, the time between the two mail can be in hours, not mere seconds. I'll edit my post
David Brunelle
A: 

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.

AaronS
What's with the downvote? At least leave have the courtesy to leave a comment when you downvote a legit answer.
AaronS