Preventing multiple POST in asp.net mvc application

How can I prevent a user from sending the same data several times if they continue to press the submit button?

I know there is a way in php to prevent this multiple submission, but I don't see any for asp.net mvc. Whether there is a?

+4
source share
4 answers

You can disable the submit button using javascript. JQuery example:

$(function() { $('form').submit(function() { $('#idofsubmitbutton').attr('disabled', 'disabled'); }); }); 

Please note that this may not be 100% reliable, as, for example, the user may disable javascript or even worse: he may have malicious intentions and automate HTTP POST requests.

+6
source

Are you looking for a post-redirect-receive strategy

Disabling the submit button does not prevent the F5 from updating.

+4
source

The best practice is to implement a PRG template (http://en.wikipedia.org/wiki/Post/Redirect/Get), I have an old article on this subject in aspnet mvc http://weblogs.asp.net/rashid/archive /2009/04/01/asp-net-mvc-best-practices-part-1.aspx check # 13.

+2
source

This is a duplicate of this question , but I am posting my answer here for convenience ...

The PRG template will not prevent this, since the P action in it takes time (usually this is the case), and the user can submit the form again (by clicking or updating the browser), which will cause the PRG template to be "unable to "

Please note that attackers can also circumvent all your client-side measures by running multiple HTTP messages in quick succession.

The solution to all of the above is to check for duplicate views on the server side using the following method described by me here .

I quote:

"If you use a hidden anti-fake token in your form (as you should), you can cache the anti-fake token on the first submission and remove the token from the cache, if necessary, or finish writing to the cache after a set amount of time."

Then you can check with each cache request whether a particular form has been submitted and reject it, if any. "

0
source

All Articles