双击/重复单击 HTML 按钮
我们的应用程序正在使用 ASP.net MVC,我们对以下场景中会发生什么有疑问。
我们有一个进行付款的“按钮”,付款后我们有一个会话变量,它将“PaymentSubscribed”标记为 True。该会话变量将根据其值用于执行不同的操作。
现在我希望您能提供意见来决定如果用户单击该“按钮”两次会发生什么。
第二个请求(第二次单击完成按钮生成)是否会等到第一个请求执行?或者第二个请求将继续进行,而不必过多担心第一个请求在哪里。
注意:我们避免使用任何客户端脚本。
Our application is using ASP.net MVC and we have a question on what happens in the below scenario.
We have a "button" which makes a payment and after making a payment we have a session variable which marks "PaymentSubmitted" to True. This session variable will be used to do different stuff based on it's value.
Now I would like to have your inputs in deciding what happens if the user clicks on that "button" twice.
Will the second request (generated from second click of the finish button) wait till the first request is executed ? Or will the second request will move on without worrying much on where is the first request.
note: we refrain from using any client side scripting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设单击按钮是表单上的“提交”。
单击该按钮后,将发布第二个请求。试想一下,您在任何给定页面上的浏览器上刷新 20 次,这 20 个请求将被发送到您的 Web 服务器,并将按照收到的顺序进行处理。
如果您足够早地设置会话变量,那么您应该能够在后续单击时检查会话变量 - 但这绝对不安全。
更好的方法是使用 JavaScript 或发布到不同的页面,以便在付款时无法再次单击该按钮。
I'm assuming the button click is a "submit" on a form.
Once the button is clicked, a second request WILL get posted. Just imagine, you hit the refresh on your browser on any given page 20 times, those 20 requests are going to be sent to your web server and will be handled in the order that they are received.
You should be able to check the session variable on the subsequent click if you've set it early enough - but this is definitly not safe.
The better approach would be to use JavaScript or post to a different page so that the button is not able to be clicked again while taking payment.
是否可以识别操作(购买产品或支付的任何内容)?在这种情况下,您可以在第一次单击后将操作标记为“正在进行”。当您的服务器收到请求时,首先要检查操作的状态,如果是“正在进行”,服务器将不会启动另一个事务。
无论如何,拥有一些客户端阻止功能(禁用按钮、带有典型等待消息的模式窗口等)是件好事,主要是为了用户,这样他们就会得到“有事情发生”的反馈。但当然不仅仅在该阻塞功能中进行中继,因为客户端的任何内容都容易被更改。
It would be possible to identify the operation (the product buy or whatever it is being payed)? In that case you can mark an operation as "in progress" after clicking the first time. When your server receives a petition, the first thing would be to check the status of the operation, if is "in progress" the server wouldn't start another transaction.
In any case is good to have some client side blocking feature (disabling the button, a modal window with the typical wait message, etc...), mainly for the user, so they have the feedback that "something is going on". But of course not relaying only in that blocking feature, because anything that is client side is susceptible to be altered.