Response.Flush() throws System.Web.HttpException

后端 未结 4 991
迷失自我
迷失自我 2021-02-05 21:31

I have a HttpHandler that I\'m using to handle certain images on a client\'s website. When I\'m outputting the image stream to the response object and call Flush occasionally an

4条回答
  •  无人共我
    2021-02-05 22:09

    I realise this is an old post but it came up when I was looking for an answer to a similar issue. The following is largely verbatim from this SO answer. More background info is available at Is Response.End() considered harmful?.

    Replace this: HttpContext.Current.Response.End();

    With this:

    HttpContext.Current.Response.SuppressContent = true;  // Gets or sets a value indicating whether to send HTTP content to the client.
    HttpContext.Current.ApplicationInstance.CompleteRequest(); // Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event.
    

提交回复
热议问题