Are you saying that a simple HTTP link is not available on the client side until the async postback is complete? If so, that sounds like a mystery, because you need to either optimize the process on the server side, or set a shorter request timeout on the server side. Either this, or redesign your user interaction to make the server-side Excel generation process asynchronous rather than synchronous so that the user does not have to wait for Excel generation to complete. You could think about it on the client side, then set a JavaScript timer to periodically request the server to find out if the file was ready, and if so, indicate that to the user and give them a link to the download file link or something kind.
Otherwise, if you could call another AJAX request, waiting for a return (that you might not hear from its sound), you can simply execute a new HTTP request that “cancels” the lengthy process. But this does not seem to work, as the server is still processing a long HTTP request. Therefore, I would prefer to explore the options in my first paragraph.
If the cancellation allowed the client to perform an asynchronous HTTP request, you can set the session state value to indicate that a cancellation was requested. Personally, I wouldn’t do that. But if you did, then your lengthy server process may periodically look for the presence of a session value. Say:
if (Session["cancel-me"] != null) { Session["cancel-me"] = null; abortThisLongProcess(); }
source share