Response.End() 和 CompleteRequest() [英] Response.End() and CompleteRequest()

查看:64
本文介绍了Response.End() 和 CompleteRequest()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Response.End()CompleteRequest() 各自的优缺点是什么?我应该和不应该在哪里使用它们?我看了这个问题,但没有得到正确的答案.

What are the advantage and disadvantage for each of Response.End() and CompleteRequest()? Where should I and should I not use them? I looked at this question but I didn't get a proper answer.

推荐答案

HttpResponse.End 将输出缓冲区刷新到客户端并终止当前的请求处理线程(这很糟糕),而 HttpApplication.CompleteRequest 告诉 ASP.NET 立即跳过 ASP.NET 管道中的所有未来阶段并直接跳转到 EndRequest 步骤(这也会引发 HttpApplication.EndRequest 事件).然后请求线程继续进行正常的生命周期结束清理.

HttpResponse.End flushes the output buffer to the client and terminates the current request-handling thread (this is bad), whereas HttpApplication.CompleteRequest tells ASP.NET to immediately skip all future stages in the ASP.NET pipeline and jump directly to the EndRequest step (which also raises the HttpApplication.EndRequest event). The request thread then proceeds with normal end-of-life cleanup.

因此,Response.End 就像一个弹射座椅:它可以迅速结束事情,但意味着您会失去控制并且可能会变得不必要地苛刻.而 CompleteRequest 就像在最近的机场紧急降落一样.

So, Response.End is like an ejector seat: it quickly ends things, but means you lose control and might be unnecessarily harsh. Whereas CompleteRequest is like making an emergency landing at the nearest airport.

这篇关于Response.End() 和 CompleteRequest()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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