
Introduction
Joe was doing online shopping, he clicked the Submit button to place an order, there was no response for 5 seconds, he thought something had gone wrong and clicked the button again!
What happened?
Joe probably got charged twice!! It was only because he could not receive the response for whatever reason, but the sever got two requests from him and placed duplicate orders for him.
Here is a solution which can prevent such kind of mistakes.
Background
Basically, this is a .NET implementation of the SynchronizerToken pattern which has been used in the Java world for years (refer to Core J2EE Patterns).
Using the code
It is pretty easy to use:
- add a reference to the
SynchronizerToken assembly in your project.
- inherit you page from the
Synchronizer page.
- add the
[OneSubmitOnly] attribute right before your page class.
[OneSubmitOnly(RedirectURL = "~/ErrorPage.aspx")]
public class WebForm1 : Synchronizer
{
.......
}
Points of Interest
- The
OneSumbmitOnly attribute has an optional RedirectURL property which points to any valid URL to where a request gets redirected when duplicated submission happens. If no RedirectURL property is set, the request gets rejected and the default message will show up.
- Resubmission is checked before any subclass event.
History
- Version: 1.0
- Creation date: 2005-09-30
- Version: 1.1
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here