How not to abort http response c#
<p>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 anything after <code>response.end()</code>.</p>

<p>for example, this is my sample code:</p>

<pre><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);
</code></pre>

<p>So, in this example StartNextMethod and Response.Redirect are not executing. </p>

<p>What I tried is I created a separate handler(ashx) with the following code:</p>

<pre><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();
        }
</code></pre>

<p>and call it like this:</p>

<pre><code>Download d = new Download();
d.ProcessRequest(HttpContext.Current);
StartNextMethod();
Response.Redirect(URL);
</code></pre>

<p>but the same error happen. I've tryied to replace Response.End with CompleteRequest but it doesn't help.</p>

<p>I guess the problem is that I'm using HttpContext.Current but should use a separate response stream. Is that correct? how do I do that in a separate method generically (Assume that I want my handler to accept byte array of data and content type and be downloadable from a separate response. I really do not want to use a separate page for a response.</p>

<p><strong>UPDATE</strong><br>
I still didn't find a good solution. I'd like to do some actions after user has downloaded a file, but without using a separate page for a response\request thing.</p>
