gpt4 book ai didi

C# - 如果用户在插入记录后刷新页面,则会创建重复记录。我怎样才能防止这种情况发生?

转载 作者:行者123 更新时间:2023-11-30 13:33:26 24 4
gpt4 key购买 nike

页面上存在的任何其他功能都是如此。我不希望在回发之前发生的最后一个事件再次发生。

最佳答案

我相信你应该看看 PRG Pattern (发布/重定向/获取)

Post/Redirect/Get (PRG) is a common design pattern for web developers to help avoid certain duplicate form submissions and allow user agents to behave more intuitively with bookmarks and the refresh button

在 ASP.NET 中:

  1. POST - 点击提交按钮导致 HTTP POST
  2. 重定向 + 获取 - HttpResponse.Redirect()

MSDN,Redirecting Users to Another Page

In server code, you can programmatically redirect by calling the Redirect method. The method sends a command to the user's browser that causes the browser to issue an HTTP GET command for the target page.

关于 PRG 模式的一些重要说明:

!!! The PRG pattern cannot address every scenario of duplicate form submission. Some known duplicate form submissions that PRG cannot solve are:

  • if a web user goes back to the web form and resubmits it.
  • if a web user clicks a submission button multiple times before the server response loads (may be prevented by using JavaScript to disable the button after the first click).
  • if a web user refreshes before the initial submission has completed because of server lag, resulting in a duplicate HTTP POST request in certain user agents.
  • if a malicious web user submits the form twice despite client-side safeguards and typical browser behavior.

关于C# - 如果用户在插入记录后刷新页面,则会创建重复记录。我怎样才能防止这种情况发生?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7820912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com