ASP.NET end response without ThreadAbortException

Posted by Joe Enos on August 17, 2021 · 1 min read

Thanks to this answer on StackOverflow for this answer:

// Sends all currently buffered output to the client.
HttpContext.Current.Response.Flush();

// Gets or sets a value indicating whether to send HTTP content to the client.
HttpContext.Current.Response.SuppressContent = true;

// Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event.
HttpContext.Current.ApplicationInstance.CompleteRequest();