Search code examples
c#jqueryfilehttphandlerresponse.write

HttpHandler write to redirected page before sending file


I can never seem to find any docs on .net, and the official ones (when they're correct) are a hopeless maze.

I redirect a user with jQuery to an HttpHandler on a new page where I build and send an html table (and call it an excel file) on the fly. I can build and send the file with no delay (even huge ones) thanks to stackers.

I'd like to tell the user on the new page that I'm building the file, etc as the file is being built and sent.

When I do context.response.write before sending my excel headers, I get:

Server Error in '/' Application.

Server cannot append header after HTTP headers have been sent.

Is there any way to achieve what I want?

Many thanks in advance!


Solution

  • What you need is a temporary landing page which redirects to the download page.

    On the temp page you can have your message and a small script to send the user to the download.

    <body>
    <div> Your file is getting created... Please wait patiently.
    </div>
    <script>
        window.location.href = 'http://yoursite.com/documentpage/blah/foo/bar';
    </script>
    </body>