Prevent duplicate record insertion on refresh without redirecting

三世轮回 提交于 2019-12-02 04:24:36

No. You'll either do a post-redirect-get or subsequent refreshes will present this dialog to the user.

In case you chose not to do a PRG, you need to somehow detect that the submission is duplicate. One easy way is to have injected a hidden parameter with a random hash/number (e.g called token). Upon submission you'll have to check that the token you expect (which you'll have probably stored in the http session) is being sent together with the other POST parameters. On valid submission you'll remove/invalidate this token. That way when a POST comes which a non recognised token then it's most probably a duplicate or out of date request.

If you implement this correctly then you'll also make your application proof to csrf attacks.

You could set some session variable after successful submission. For each submission you check whether the variable is set or not, on you make an insertion of data.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!