How not to abort http response c#

前端 未结 8 704
刺人心
刺人心 2020-12-18 03:34

I need to run several methods after sending file to a user for a download. What happens is that after I send a file to a user, response is aborted and I can no longer do any

8条回答
  •  情话喂你
    2020-12-18 04:11

    I recommend this solution :

    1. Don't use response.End();

    2. Declare this global var : bool isFileDownLoad;

    3. Just after your (Response.BinaryWrite(a);) set ==> isFileDownLoad = true;

    4. Override your Render like :

      /// /// AEG : Very important to handle the thread aborted exception /// /// override protected void Render(HtmlTextWriter w) { if (!isFileDownLoad) base.Render(w); }

提交回复
热议问题