How to prevent repeated postbacks from confusing my business layer(如何防止重复回发混淆我的业务层)
问题描述
我有一个采用传统 3 层设计的 Web 应用程序 (ASP.Net 3.5).如果用户单击一个按钮,则会发生回发,一些中间层和数据层代码会运行,并且屏幕会刷新.如果用户在第一次回发完成之前多次单击该按钮,我的逻辑会变得混乱,并且应用程序可能最终处于无效状态.预防这种情况的最佳方法是什么?
I have a web application (ASP.Net 3.5) with a conventional 3 layer design. If the user clicks a button a postback happens, some middle and data layer code runs, and the screen is refreshed. If the user clicks the button multiple times before the first postback is completed my logic gets confused and the app can end up in an invalid state. What are the best ways to prevent this?
我可以使用 javascript 来禁用按钮,但这只是隐藏了问题.如何构建我的业务和数据层来处理这个问题?
I can use javascript to disable the button but this just hides the problem. How do I build my business and data layers to handle this?
推荐答案
最流行的三种方法(经常串联使用)是:
The three most popular methods (which are often used in tandem) are:
- 禁用提交按钮一旦点击/按下;
- 使用 POST+REDIRECT+GET 避免返回按钮问题;和
- 替换浏览器中的历史记录 所以你不能去返回(但应谨慎使用,并有充分的理由).
- Disable submit buttons once clicked/pressed;
- Use POST+REDIRECT+GET to avoid back button issues; and
- Replace history in the browser so you can't go back (but this should be used sparingly and with good reason).
这篇关于如何防止重复回发混淆我的业务层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何防止重复回发混淆我的业务层


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01