本文介绍了什么是使用到Response.End(假)VS ApplicationInstance.CompleteRequest /用例之间的差异()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跨讨论了使用的SO问题就来了 ApplicationInstance.CompleteRequest()来避免 ThreadAbortException 是当抛出到Response.End()被调用。

I came across an SO question that discussed the use of ApplicationInstance.CompleteRequest() to avoid a ThreadAbortException being thrown when Response.End() is called.

在过去,为了避免我上面提到的异常错误,我用这个重载:到Response.End(假)

In the past, to avoid the exception error I mentioned above, I have used this overload: Response.End(false).

我想了解什么是这两种方法之间的差异。为什么我会选择使用 ApplicationInstance.CompleteRequest()代替到Response.End(假)

I am trying to understand what are the differences between the two methods. Why would I choose to use ApplicationInstance.CompleteRequest() in place of Response.End(false)?

编辑:

据我所知, ApplicationInstance.CompleteRequest()是做事情的更多的正确的方式,但一个特点,调用到Response.End(真)所缺少的是不会处理后面的code的其余部分。有时候,我们不想继续加工,但要结束执行权那里,然后。

I understand that ApplicationInstance.CompleteRequest() is the more correct way of doing things, but the one feature that calling Response.End(true) that is missing is not processing the rest of the code that follows. Sometimes, we do not want to continue with the processing, but want to end the execution right there and then.

也许在这里回答我的问题,但也许这样做事情的正确方法是这样结束的时候响应(而不是中止线程),有code的没有行写code处理。

Maybe answering my own question here, but maybe the correct way of doing things is to write the code so that when ending the response (and not aborting the thread), there are no more lines of code to process.

一个例子:

[DO SOME WORK]
if ([SOME CONDITION])
{
     ApplicationInstance.CompleteRequest();
}
else
{
    //continue processing request
}

这可以工作,但它似乎像我们这里的编码处理的方法的局限性。并可能导致有些凌乱code。

This may work, but it seems like we are coding here to deal the limitations of the method. And can lead to some messy code.

我失去了一些东西在这里?

Am I missing something here?

推荐答案

<一个href=\"http://weblogs.asp.net/hajan/archive/2010/09/26/why-not-to-use-htt$p$psponse-close-and-htt$p$psponse-end.aspx\" rel=\"nofollow\">http://weblogs.asp.net/hajan/archive/2010/09/26/why-not-to-use-htt$p$psponse-close-and-htt$p$psponse-end.aspx

从文章:而不是使用的Htt presponse.End和Htt的presponse.Close方法,最好是使用的HttpApplication.CompleteRequest方法,这样即对缓存的响应数据服务器,客户端或两者之间不会掉下来。

From article: "instead of using the HttpResponse.End and HttpResponse.Close methods, the best would be to use the HttpApplication.CompleteRequest method, so that the response data that is buffered on the server, the client or in between won’t get dropped."

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("Hello Hajan");
    Response.End();            
    Response.Write("<br />Goodbye Hajan");
}
Output: Hello Hajan

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("Hello Hajan");
    this.Context.ApplicationInstance.CompleteRequest();
    Response.Write("<br />Goodbye Hajan");
}

Output: Hello Hajan 
Goodbye Hajan

http://blogs.msdn.com/b/aspnetue/archive/2010/05/25/response-end-response-close-and-how-customer-feedback-helps-us-improve-msdn-documentation.aspx

从文章:HttpApplication.CompleteRequest是一个更好的方式来结束请求

From article: "HttpApplication.CompleteRequest is a better way to end a request."

这篇关于什么是使用到Response.End(假)VS ApplicationInstance.CompleteRequest /用例之间的差异()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 17:40