• <legend id='hHQ2X'><style id='hHQ2X'><dir id='hHQ2X'><q id='hHQ2X'></q></dir></style></legend>
    <tfoot id='hHQ2X'></tfoot>

      • <bdo id='hHQ2X'></bdo><ul id='hHQ2X'></ul>

      <small id='hHQ2X'></small><noframes id='hHQ2X'>

      1. <i id='hHQ2X'><tr id='hHQ2X'><dt id='hHQ2X'><q id='hHQ2X'><span id='hHQ2X'><b id='hHQ2X'><form id='hHQ2X'><ins id='hHQ2X'></ins><ul id='hHQ2X'></ul><sub id='hHQ2X'></sub></form><legend id='hHQ2X'></legend><bdo id='hHQ2X'><pre id='hHQ2X'><center id='hHQ2X'></center></pre></bdo></b><th id='hHQ2X'></th></span></q></dt></tr></i><div id='hHQ2X'><tfoot id='hHQ2X'></tfoot><dl id='hHQ2X'><fieldset id='hHQ2X'></fieldset></dl></div>

        为什么我会收到“发送 HTTP 标头后无法重定向"?当我调用 Response.Redirect() 时?

        时间:2023-10-25

          <tfoot id='3Rny9'></tfoot>
            <tbody id='3Rny9'></tbody>
          1. <small id='3Rny9'></small><noframes id='3Rny9'>

            1. <i id='3Rny9'><tr id='3Rny9'><dt id='3Rny9'><q id='3Rny9'><span id='3Rny9'><b id='3Rny9'><form id='3Rny9'><ins id='3Rny9'></ins><ul id='3Rny9'></ul><sub id='3Rny9'></sub></form><legend id='3Rny9'></legend><bdo id='3Rny9'><pre id='3Rny9'><center id='3Rny9'></center></pre></bdo></b><th id='3Rny9'></th></span></q></dt></tr></i><div id='3Rny9'><tfoot id='3Rny9'></tfoot><dl id='3Rny9'><fieldset id='3Rny9'></fieldset></dl></div>
                <bdo id='3Rny9'></bdo><ul id='3Rny9'></ul>

                <legend id='3Rny9'><style id='3Rny9'><dir id='3Rny9'><q id='3Rny9'></q></dir></style></legend>

                • 本文介绍了为什么我会收到“发送 HTTP 标头后无法重定向"?当我调用 Response.Redirect() 时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我调用 Response.Redirect(someUrl) 我得到以下 HttpException:

                  When I call Response.Redirect(someUrl) I get the following HttpException:

                  发送 HTTP 标头后无法重定向.

                  Cannot redirect after HTTP headers have been sent.

                  为什么我会得到这个?我该如何解决这个问题?

                  Why do I get this? And how can I fix this issue?

                  推荐答案

                  根据Response.Redirect(string url)的MSDN文档,当尝试重定向之后会抛出HttpExceptionHTTP 标头已发送".由于 Response.Redirect(string url) 使用 Http "Location" 响应标头 (http://en.wikipedia.org/wiki/HTTP_headers#Responses),调用它将导致标头发送到客户端.这意味着如果您第二次调用它,或者如果您在以其他方式发送标头后调用它,您将获得 HttpException.

                  According to the MSDN documentation for Response.Redirect(string url), it will throw an HttpException when "a redirection is attempted after the HTTP headers have been sent". Since Response.Redirect(string url) uses the Http "Location" response header (http://en.wikipedia.org/wiki/HTTP_headers#Responses), calling it will cause the headers to be sent to the client. This means that if you call it a second time, or if you call it after you've caused the headers to be sent in some other way, you'll get the HttpException.

                  防止多次调用 Response.Redirect() 的一种方法是在调用之前检查 Response.IsRequestBeingRedirected 属性 (bool).

                  One way to guard against calling Response.Redirect() multiple times is to check the Response.IsRequestBeingRedirected property (bool) before calling it.

                  // Causes headers to be sent to the client (Http "Location" response header)
                  Response.Redirect("http://www.stackoverflow.com");
                  if (!Response.IsRequestBeingRedirected)
                      // Will not be called
                      Response.Redirect("http://www.google.com");
                  

                  这篇关于为什么我会收到“发送 HTTP 标头后无法重定向"?当我调用 Response.Redirect() 时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何从 http 标头获取文件大小 下一篇:ASP.NET MVC 和 IE 缓存 - 操作响应标头无效

                  相关文章

                • <i id='lSSYM'><tr id='lSSYM'><dt id='lSSYM'><q id='lSSYM'><span id='lSSYM'><b id='lSSYM'><form id='lSSYM'><ins id='lSSYM'></ins><ul id='lSSYM'></ul><sub id='lSSYM'></sub></form><legend id='lSSYM'></legend><bdo id='lSSYM'><pre id='lSSYM'><center id='lSSYM'></center></pre></bdo></b><th id='lSSYM'></th></span></q></dt></tr></i><div id='lSSYM'><tfoot id='lSSYM'></tfoot><dl id='lSSYM'><fieldset id='lSSYM'></fieldset></dl></div>

                  <small id='lSSYM'></small><noframes id='lSSYM'>

                  <legend id='lSSYM'><style id='lSSYM'><dir id='lSSYM'><q id='lSSYM'></q></dir></style></legend>

                      • <bdo id='lSSYM'></bdo><ul id='lSSYM'></ul>
                      <tfoot id='lSSYM'></tfoot>