IIS7集成管道-Response.End未结束请求

发布于 2024-08-26 10:36:27 字数 488 浏览 5 评论 0原文

在我们升级到 IIS7 中的集成管道之前,我有以下代码可以按预期工作。

public void RedirectPermanently(string url, bool clearCookies)
{
  Response.ClearContent();
  Response.StatusCode = 301;
  Response.AppendHeader("Location", url);
  if(clearCookies)
  {
    Response.Cookies.Clear();
    Response.Flush();
    Response.End();
  }
}

以前执行此方法时,如果clearCookies为true,则响应将发送到客户端,请求处理将结束。现在在集成管道 Response.End() 下似乎没有结束处理。该页面继续运行,就好像该方法从未被调用过一样。

大问题是,为什么发生变化以及发生了什么变化!

谢谢。

I have the following bit of code that worked as expected before we upgraded to Integrated Pipeline in IIS7.

public void RedirectPermanently(string url, bool clearCookies)
{
  Response.ClearContent();
  Response.StatusCode = 301;
  Response.AppendHeader("Location", url);
  if(clearCookies)
  {
    Response.Cookies.Clear();
    Response.Flush();
    Response.End();
  }
}

Previously when this method was executed, if clearCookies was true, the response would be sent to the client and request processing would end. Now under Integrated Pipeline Response.End() does not seem to end processing. The page continues running as if the method was never called.

Big question is, why and what changed!

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千里故人稀 2024-09-02 10:36:27

HttpContext.IsInCancellablePeriod 为 true 时,Response.End 只会引发 ThreadAbortException

Response.Flush() 的一个副作用是,在集成管道模式下执行时,会导致 HttpContext.IsInCancellablePeriod 变为 false。

尝试从代码中删除 Response.Flush() 。无论如何,结束响应都会导致响应流被刷新。

Response.End will only raise ThreadAbortException when HttpContext.IsInCancellablePeriod is true.

One side effect of Response.Flush() is that is causes HttpContext.IsInCancellablePeriod to become false when executing in integrated pipeline mode.

Try removing Response.Flush() from your code. Ending the response will cause the response stream to be flushed anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文