防止双击按钮 [英] Prevent double-clicking on Button

查看:91
本文介绍了防止双击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用户双击Web应用程序上的操作按钮时遇到问题,这意味着将重复的记录添加到我的数据库中,有时会向用户收取两次费用(因为该操作被执行了两次)

防止ASP.NET双击的最佳方法是什么?

解决方案

我看到您在未启用JavaScript的用户面前对此感到担忧.如果是这种情况,则需要在服务器端进行处理.解决此问题的一种方法是在整个过程中实施 CSRF令牌您的应用.

这基本上在服务器端会话中保留令牌,并且还要求在请求中提交令牌.及时在会话中向您提供此令牌(并假设您使用常规的ASP.Net机制来序列化对会话的访问),第二个请求将使用过期的令牌,可以忽略./p>

I keep having an issue with users double-clicking on action buttons on my web application, which is meaning duplicate records are being added into my database, and sometimes the user is being charged twice (as the action is being ran twice).

What is the best way of preventing double clicking in ASP.NET?

解决方案

I see you're concerned about this in the face of users without javascript enabled. If that's the case, you need to deal with it on the server side. One idea to deal with this would be to implement CSRF tokens throughout your app.

This basically keeps a token in the server side session, and also requires the token to be submitted in the request. Provided youreset this token in the session in a timely manner (and assuming that you're using usual ASP.Net mechanisms to serialize access to the session), the second request will be using an out of date token, and can be ignored.

这篇关于防止双击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆