[英]Postback cause browser confirmation before refreshing (F5)
When I do a postback
, why the browser always ask me a confirmation before refreshing ? 当我进行
postback
,为什么浏览器在刷新之前总是询问我确认信息? (F5 / CTRL + F5) (F5 / CTRL + F5)
My code is really simple (I use a master page) : 我的代码非常简单(我使用母版页):
.aspx 的.aspx
...
<asp:button runat="server" ClientIDMode="static" type="button" id="btnlogin"
OnClientClick="return veriflogin();" class="btn btn-primary" Text="Valider"
onclick="btnlogin_Click"></asp:button>
<asp:Label ID="ok" runat="server" Visible="false" Text="allright"></asp:Label>
...
.cs 的.cs
protected void btnlogin_Click(object sender, EventArgs e)
{
ok.Visible = true;
}
The confirmation (IE): 确认(IE):
Can I avoid this confirmation ? 我可以避免这种确认吗?
Postback occurs (as name suggests) using POST
HTTP verb. 回传发生(顾名思义)使用
POST
HTTP动词。 POST
by definition is not idempotent , and thus repeating the same request is not necessarily safe. 根据定义 ,
POST
不是幂等的 ,因此重复相同的请求不一定安全。 In other words, repeating POST
may result in different end result than doing it once. 换句话说,重复
POST
可能会导致最终结果不同于一次。 Hence the browser warns you that in order to retrieve the page again, it has to repeat POST
operation which may have unintended consequences. 因此,浏览器警告您,为了再次检索该页面,它必须重复
POST
操作,这可能会带来意想不到的后果。
For example, in RESTful applications , POST
implies "create" (as in CRUD, akin to SQL's INSERT
) a resource. 例如,在RESTful应用程序中 ,
POST
意味着“创建”资源(如在CRUD中,类似于SQL的INSERT
)。 Executing POST
twice means two instances of the resource will be created rather than one. 执行两次
POST
意味着将创建两个资源实例,而不是一个。 Compare it with GET
which is a read operation, and reading the same resource more than once does not affect the state of the resource(s), and is thus considered safe (because GET
is idempotent) 将它与作为读取操作的
GET
进行比较,并且多次读取同一资源不会影响资源的状态,因此被认为是安全的(因为GET
是幂等的)
No, you can't avoid the confirmation. 不,您无法避免确认。
If your last action on a site was a POST, most browsers will ask for a confirmation on whether you want to refresh the site with the same POST again. 如果您对站点的最后一次操作是POST,则大多数浏览器都会要求您确认是否要使用相同的POST重新刷新站点。 That's intended behavior.
这是预期的行为。
POST requests are intended to modify state in one way or another. POST请求旨在以一种或另一种方式修改状态。 That's why your browser warns you.
这就是为什么浏览器警告您的原因。 GET requests should not modify state, and are therefore considered "safe" to resubmit.
GET请求不应修改状态,因此被视为“安全”重新提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.