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( ...
随机推荐
- 前端JavaScript高级面试笔记
一.ES6 1.模块化 ES6通过export和import实现模块化 ES6的模块化的基本规则或特点, 欢迎补充: 1:每一个模块只加载一次, 每一个JS只执行一次, 如果下次再去加载同目录下同文件 ...
- https-配置使用HTTPS的ASP.NET Web应用
有关HTTPS.SSL以及SSL证书的工作原理,参见 <HTTPS-HTTPS原理> <HTTPS-SSL证书> <HTTPS-攻击实例与防御> 本文将演示如何在I ...
- mysql添加事件
begin declare debug int; set @debug = 0; if @debug = 1 then insert into task_monitor(info) values('s ...
- Codeforces 219C Color Stripe(思维+字符串)
题目链接:http://codeforces.com/problemset/problem/219/C 题目大意: 给出一个字符串,只包含k种字符,问最少修改多少个字符(不增长新的种类)能够得到一个新 ...
- Win7建立FTP站点
Win7建立FTP站点 1.到控制面板---程序---打开或关闭windows功能,列表内找到 Internet信息服务(展开)---选中FTP的三个项: 2.到控制面板---系统和安全---管理工具 ...
- CSS------如何让大小不一样的div中心对齐
如图: 代码: <div style = 'display:inline;color:green;font-size:30px;font-weight:bold'>¥1666.00< ...
- SpringBoot的Controller使用
一: 1.注解 2.control注解 3.效果 4.RespomseBody package com.caojun.springboot; import org.springframework.be ...
- Javascript中DOM详解与学习
DOM(文档对象模型)是针对html和XML文档的一个API(应用程序编程接口).DOM描绘了一个层次化的节点树,允许开发人员添加,移除和修改页面的某一部分.下面将从这几个层次来学习. 一.节点层次 ...
- codeforces_1092c
title: codeforces_1092c date: 2018-12-24 19:42:23 tags: acm 刷题 概述 一道有关字符串前缀后缀的题,,,自己迟早要坑在这字符串的题上,,,一 ...
- Orleans核心功能
一.Grain持久性 二.定时器和提醒 三.依赖注入 四.观察者 五.无状态工作者Grains 六.流 一.Grain持久化 1,Grain持久化目标 ①允许不同类型的存储提供者使用不同类型的存储提供 ...