How not to abort http response c#

前端 未结 8 690
刺人心
刺人心 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:16

    As the previous answers had stated - returning PDF file means to send HTTP headers. You cannot send another headers after that, and Response.Redirect() simply means to send HTTP 302.

    If you don't want to have separate page, or if you don't want to use AJAX, why not trying:

    <head>
        <meta http-equiv="refresh" content="3; url=http://www.site.com/download.aspx?xxxx">
    </head>
    

    Actually this will show the desired page you want to show to the user, and will refresh the page after 3 sec with the URL for download of the PDF file.

    0 讨论(0)
  • 2020-12-18 04:17

    Response.End() throws a thread abort exception. It is designed to end your response. No code after that will process in that thread.

    The End method causes the Web server to stop processing the script and return the current result. The remaining contents of the file are not processed.

    What is it that you are trying to achieve?

    If your purpose it to allow the pdf to download and then take the user to some other page, a little javascript can help you out.

    Add a script with a timer to set location.href to your redirected paged.

    0 讨论(0)
提交回复
热议问题