HttpResponse.End 方法

定义

将当前所有缓冲的输出发送到客户端,停止该页的执行,并引发 EndRequest 事件。Sends all currently buffered output to the client, stops execution of the page, and raises the EndRequest event.

public:
 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.net 中的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.

如果该End方法无法ThreadAbortException引发,则它会将响应字节刷新到客户端。If 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.

适用于