HttpResponse.End 方法


將目前所有受緩衝的輸出傳送到用戶端、停止網頁的執行,並引發 EndRequest 事件。Sends all currently buffered output to the client, stops execution of the page, and raises the EndRequest event.

 void End();
public void End ();
member this.End : unit -> unit
Public Sub End ()


End() 呼叫已終止目前要求。The call to End() has terminated the current request.


這個方法只是為了與 ASP 相容性而提供,也就是為了與之前 ASP.NET 的 COM 架構 Web 程式設計技術相容。This method is provided only for compatibility with ASP - that is, for compatibility with COM-based Web-programming technology that preceded ASP.NET. 如果您想要跳到EndRequest事件並傳送回應給用戶端,通常最好改為呼叫。 CompleteRequestIf you want to jump ahead to the EndRequest event and send a response to the client, it is usually preferable to call CompleteRequest instead.

為了模仿 ASP 中End方法的行為,這個方法會嘗試ThreadAbortException引發例外狀況。To mimic the behavior of the End method in ASP, this method tries to raise a ThreadAbortException exception. 如果此嘗試成功,呼叫的執行緒將會中止,這對您的網站效能會造成損害。If this attempt is successful, the calling thread will be aborted, which is detrimental to your site's performance. 在此情況下,執行End方法的呼叫之後,不會有任何程式碼。In that case, no code after the call to the End method is executed.

如果方法無法ThreadAbortException引發,它會改為將回應位元組排清至用戶端。 EndIf the End method is not able to raise a ThreadAbortException, it instead flushes the response bytes to the client. 它會同步執行,這也可能會對您的網站效能造成危害。It does this synchronously, which can also be detrimental to your site's performance.

不論是哪一種情況(無論ThreadAbortException是否成功引發例外狀況),回應管線都會向前跳EndRequest到事件。In either case (whether or not a ThreadAbortException exception is successfully raised), the response pipeline jumps ahead to the EndRequest event.

方法不會引發例外狀況,而在呼叫CompleteRequest方法之後,可能會執行程式碼。 CompleteRequestThe CompleteRequest method does not raise an exception, and code after the call to the CompleteRequest method might be executed. 如果您想要避免執行後續的程式碼,而且如果可接受的效能End損失,您可以呼叫End ,而不CompleteRequest是。If your intention is to avoid execution of subsequent code, and if the performance penalty of End is acceptable, you can call End instead of CompleteRequest.