页面重新加载是否会导致发布? [英] Does page reload ever cause post?

查看:27
本文介绍了页面重新加载是否会导致发布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速提问,我已经尝试过自己解决这个问题,但是在尝试找出页面重新加载的原因或方式以及执行/不执行它应该执行的操作时,会话变量的使用可能会令人困惑.

Quick question, I have tried figuring this out myself, but the use of Session Variables can be confusing when trying to figure out why or how a page is reloading and doing/not doing what it is supposed to do.

页面重新加载(使用 JavaScript、f5、ctrl+f5、浏览器重新加载按钮等)是否会在任何(非脚本化)情况下导致表单重新发布?

Does a page reload (with JavaScript, f5, ctrl+f5, browser reload button, etc) ever, under any (non-scripted) circumstance cause a form repost?

(这与在 C# 代码中使用 IfPost 分支有关,如下面的示例代码):

(This pertains to using IfPost branches within C# code like the example code below):

if(IsPost)
{
    //stuff that only executes if the previous request was a post.
}

我只是需要知道这里会发生什么,以便我可以正确诊断我的会话状态问题.

I just kind of need to know what to expect here so I can properly diagnose my session state problems.

感谢您的帮助!

(另外,对不起,如果我把这个问题简单化了.我意识到它可能"比一个简单的答案所能提供的更复杂).

(Also, sorry if I am oversimplifying this question. I realize that it 'may' be more complicated than a simple answer can provide).

******更新**********另外,我在 StackOverflow 上在这里寻找了这个问题的副本,但我什么也没看到,所以如果这是一个重复的问题,我深表歉意.

******UPDATE********** Also, I looked for copies of this question here, on StackOverflow, but I didn't see anything, so if this is a duplicate question, I apologize.

这里的两个答案都是很好的答案.我接受了也为我的问题提供解决方案的答案,虽然 PRG 不是唯一"的方法,但它似乎可能是最好的.这似乎也是处理客户端用户友好性的一种日益增长的方式,恕我直言,这似乎是一个很好的习惯.

Both of the answers here are good answers. I accepted the answer that also offered a solution to my question, and while PRG is not the 'only' way to do it, it seems like it may be the best. It also seems a growing way to handle client-side user-friendliness, and imho, seems like it would be a great habit to get into.

谢谢你给我看!

推荐答案

是的.如果页面是使用 POST 数据加载的,则会发生这种情况.为了防止这种情况,您需要实施 POST/REDIRECT/GET 模式.

Yes. If the page was loaded using POST data this will occur. To prevent this you need to implement the POST/REDIRECT/GET pattern.

发布/重定向/获取 (PRG) 是一种 Web 开发设计模式,可防止某些重复的表单提交,为用户代理(用户)创建更直观的界面.PRG 以一种可预测的方式支持书签和刷新按钮,不会创建重复的表单提交.

Post/Redirect/Get (PRG) is a web development design pattern that prevents some duplicate form submissions, creating a more intuitive interface for user agents (users). PRG supports bookmarks and the refresh button in a predictable way that does not create duplicate form submissions.

这篇关于页面重新加载是否会导致发布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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