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(转载)的更多相关文章
- Handling duplicate form submission in Spring MVC
javaweb开发之防止表单重复提交 - u012843873的博客 - CSDN博客 https://blog.csdn.net/u012843873/article/details/5526212 ...
- ASP.NET MVC模型绑定的6个建议(转载)
ASP.NET MVC模型绑定的6个建议 发表于2011-08-03 10:25| 来源博客园| 31 条评论| 作者冠军 validationasp.netmvc.netasp 摘要:ASP.NET ...
- Choosing web framework: ASP.NET MVC vs Django Python vs Ruby on Rails(转载)
来源:http://podlipensky.com/2012/06/choosing-web-framework-asp-net-mvc-vs-django-python-vs-ruby-on-rai ...
- Asp.Net MVC学习总结之过滤器详解(转载)
来源:http://www.php.cn/csharp-article-359736.html 一.过滤器简介 1.1.理解什么是过滤器 1.过滤器(Filters)就是向请求处理管道中注入额外的 ...
- ASP.NET MVC:模块化/插件式架构实现(转载)
I’ve recently spent quite a lot of time researching and prototyping different ways to create a plugi ...
- asp.net mvc Model验证总结及常用正则表达式【转载】
关于Model验证官方资料: http://msdn.microsoft.com/zh-cn/library/system.componentmodel.dataannotations.aspx AS ...
- ASP.NET MVC SSO单点登录设计与实现(转载)
实验环境配置 HOST文件配置如下: 127.0.0.1 app.com127.0.0.1 sso.com IIS配置如下: 应用程序池采用.Net Framework 4.0 注意IIS绑定的域名, ...
- ASP.NET MVC中,动态处理页面静态化 【转载】
首先解释一下什么是动态处理页面静态化 对于需要静态化的页面,第一次访问某个Action时,会先执行Action,并在页面渲染后向Response和服务器中网站的目录下都写入需要返回的html,而第二次 ...
- asp.net mvc model attribute and razor and form and jquery validate 完美结合
1.创建Model,添加标注. [Serializable] public class BaseUserModel:BaseModel { [StringLength(100)] [Required( ...
随机推荐
- 2、Centos6 安装tomcat8.5.31
1.下载 安装包 wget http://mirrors.aliyun.com/apache/tomcat/tomcat-8/v8.5.31/bin/apache-tomcat-8.5.31.tar. ...
- (转)jquery serialize表单序列化,当radio或checkbox 未选中时,没有序列化到对象中的原因分析和解决方案 - ghostsf
相信很多人都用过jq的表单序列化serialize()方法,因为这能很方便地帮你把表单里所有的非禁用输入控件序列化为 key/value 对象,不需要你再去一个个地拼接参数了. 这是一个很好用的函数, ...
- Java 日期时间获取和显示
Java正确获取星期Calendar.DAY_OF_WEEKhttp://chamcon.iteye.com/blog/2144433 Java SimpleDateFormat 中英文时间格式化转换 ...
- .NetCore SkyWalking APM实现服务器监控环境安装及基础使用
下载Java 8 SDK wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fw ...
- Java第三阶段学习(十、XML学习)
一.XML学习 1.模拟Servlet执行 在学习完前端及java与数据库后,将进行WEB编程阶段的学习.在WEB编程中,可以通过浏览器访问WEB服务器上的数据.这时WEB服务器就相当于另一台计算机. ...
- 关于gitignore无效的一些记录
git 远程上已经有了 .idea *.iml文件 拉到本地之后,添加.gitignore 此时由于远程有了这些文件,所以.gitignore无法忽略这些文件了 挽救做法: 思路是在本地的git缓存中 ...
- fpm 制作rpm包
使用fpm命令制作rpm包并安装 工作中有如下情况需要将文件打包rpm: 避免重复工作,将源码程序打包为rpm 使用yum发布项目,项目打包为rpm 将自己写好的程序打包为rpm,提供给用户下载 其他 ...
- maven deploy上传私服出错
error 内容如下 Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5: deploy (default ...
- mysql存储引擎innodb、myisam区别
MyISAM与InnoDB的区别是什么? 1. 存储结构 MyISAM:每个MyISAM在磁盘上存储成三个文件.第一个文件的名字以表的名字开始,扩展名指出文件类型..frm文件存储表定义.数据文件的扩 ...
- HDU 4709 3-idiots FFT 多项式
http://acm.hdu.edu.cn/showproblem.php?pid=4609 给一堆边,求这一堆边随便挑三个能组成三角形的概率. 裸fft,被垃圾题解坑了还以为很难. 最长的边的长度小 ...