Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8037559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:57:53+00:00 2026-06-05T02:57:53+00:00

I need to run several methods after sending file to a user for a

  • 0

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 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 are not executing.

What I tried is I created 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 call it like this:

Download d = new Download();
d.ProcessRequest(HttpContext.Current);
StartNextMethod();
Response.Redirect(URL);

but the same error happen. I’ve tryied to replace Response.End with CompleteRequest but it doesn’t help.

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.

UPDATE
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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:57:54+00:00Added an answer on June 5, 2026 at 2:57 am

    Update
    Since you said no second page, do this instead. Add a section to your page that checks for a query string parameter (something like fileid, or path, etc…). If this value is present then it initiates the download process using your existing code. If this value is not present then it runs like normal.

    Now when the user clicks the download link you perform a post back (which you are already doing). In this post back create an iFrame on the page and set the URL of the iFrame to your pages URL with the added query string parameter (mypage.aspx?id=12664 or ?download=true, something like that). After creating the iframe perform what ever additional databinds/etc… you wish too.

    Example
    – http://encosia.com/ajax-file-downloads-and-iframes/

    This above linked example uses an iFrame and an update panel, just like you are talking about.

    Original Post
    Response.Flush will allow you to continue processing after you send the file to the user, or just don’t call Response.End (you don’t really need too).

    However Daniel A. White is correct, you can’t actually redirect from your code after you send a file, you will get an error if you try. BUT you can continue to perform other server side operations if you need to.

    Other answers agree with the general consensus, you can’t redirect after a file starts downloading: https://stackoverflow.com/a/822732/328968 (PHP, but same concepts since it involves HTTP in general). or Directing to a new page after downloading a file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For reasons that are irrelevant to this question I'll need to run several SQLite
I need to run a command on the command-line that asks for a user
I have a large table with a multi-part index. I need to run several
i need run code that will create a database and populate tables. i am
I need to run a command,but that don't lock my application until exit of
I've heard it said several times that if you need to dynamically downcast then
I need to ship an app that uses read-only access to several preexisting SQLite3
I have a large disk file (around 8 GB) containing several million records that
I need run ts:reindex when smth add in model or destroy from model. How
I need to run a java application (not an applet or JNLP, but a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.