I need to run several methods after sending the file to the user for download. It happens that after sending the file to the user, the response is interrupted, and I can do nothing else after response.end() .
for example, this is my sample code:
  Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=test.pdf"); Response.ContentType = "application/pdf"; byte[] a = System.Text.Encoding.UTF8.GetBytes("test"); Response.BinaryWrite(a); Response.End(); StartNextMethod(); Response.Redirect(URL); 
So, in this example, StartNextMethod and Response.Redirect not executed.
I tried to create a separate handler (ashx) with the following code:
 public void ProcessRequest(HttpContext context) { context.Response.Clear(); context.Response.AddHeader("content-disposition", "attachment; filename=test.pdf"); context.Response.ContentType = "application/pdf"; byte[] a = System.Text.Encoding.UTF8.GetBytes("test"); context.Response.BinaryWrite(a); context.Response.End(); } 
and name it as follows:
 Download d = new Download(); d.ProcessRequest(HttpContext.Current); StartNextMethod(); Response.Redirect(URL); 
but the same error occurs. I tried replacing Response.End with CompleteRequest, but that does not help.
I think the problem is that I am using HttpContext.Current, but should use a separate response stream. It's right? how to do this in a separate method in the general case (suppose I want my handler to accept an array of data bytes and a content type and can be loaded from a separate answer. I really don't want to use a separate page for the response.
UPDATE
I still haven't found a good solution. I would like to do some actions after the user has downloaded the file, but not using a separate page for the answer \ request.
source share