日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

ASP.NET MVC:4 Ways To Prevent Duplicate Form Submission(转载)

發布時間:2025/5/22 121 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ASP.NET MVC:4 Ways To Prevent Duplicate Form Submission(转载) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文地址:http://technoesis.net/prevent-double-form-submission/。

Double form submission in a multi-user web based application the most common and critical issue as well.?There are many scenarios where we face duplicate submission problem like,

  • Clicking submit button twice.
  • Using Refresh button.
  • Using browser back button traverse back and re-submitting the form.
  • Using browser history feature and re-submit the form.
  • Duplicate HTTP requests?from browser.

?

There are several ways to Prevent double form submission

Disable the Submit Button.?Use JavaScript to?disable?the button a few ms after click. This will avoid multiple submits being caused by impatient users clicking multiple times on the button.??A weakness of this is if clients have JavaScript disabled.

My previous post shows a nice way to?prevent double form submission?using a jQuery plugin.

The Post / Redirect / Get pattern.?Send a redirect after submit, this is known as?Post-Redirect-Get (PRG) pattern.?In short, when the user posts the form, you perform a client side redirect (after consuming the post data) to the response (success) page.

This will avoid multiple submits being caused by users pressing F5 on the result page and ignoring the browser warning that the data will be resend, or navigating back and forth by browser back/forward buttons and ignoring the same warning.

Store a?Unique?Token in the session.?Generate an unique token when the page is requested and put in both the session scope and as hidden field of the form. During processing, check if the token is there and then remove it immediately from the session and continue processing.

If you get a form submission without a valid token, it means that the form has already been submitted and ignore it.

This has the added advantage of adding XSRF protection to your project.

Add Constraint in Database.?Change the database to not allow duplicates by adding an unique constraints or creating a unique index. A unique index is an index that requires that each value of the indexed field is unique. This is the most effective solution for preventing double request’s impact.

How do you overcome double submission? What is a real life example of a problem caused by double submits?

Some Good Links

  • Simple Synchronizer Token with Spring MVC
  • Struts: prevent form double submission with saveToken?
  • Hot answers on stackoverflow

?

總結

以上是生活随笔為你收集整理的ASP.NET MVC:4 Ways To Prevent Duplicate Form Submission(转载)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。