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

  • Home
  • SEARCH
  • 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 8969265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:34:06+00:00 2026-06-15T17:34:06+00:00

I have a controller class which inherits from ApiController and handles HTTP requests from

  • 0

I have a controller class which inherits from ApiController and handles HTTP requests from a client.

One of the actions generates a file on the server and then sends it to the client.

I’m trying to figure out how to clean up the local file once the response has been fulfilled.

Ideally this would be done through an event which fires once a response has been sent to the client.

Is there such an event? Or is there a standard pattern for what I’m trying to achieve?

[HttpGet]
public HttpResponseMessage GetArchive(Guid id, string outputTypes)
{
    //
    // Generate the local file
    //
    var zipPath = GenerateArchive( id, outputTypes );

    //
    // Send the file to the client using the response
    //
    var response = new HttpResponseMessage(HttpStatusCode.OK);
    var stream = new FileStream(zipPath, FileMode.Open);
    response.Content = new StreamContent(stream);
    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
    response.Content.Headers.ContentLength = new FileInfo(zipPath).Length;
    response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
    {
        FileName = Path.GetFileName(zipPath)
    };

    return response;
}
  • 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-15T17:34:07+00:00Added an answer on June 15, 2026 at 5:34 pm

    Take a look at the OnResultExecuted event – you can add a custom filter to the method and handle the event there.

    public class CustomActionFilterAttribute : ActionFilterAttribute
    {
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
             ///filterContext should contain the id you will need to clear up the file.
        }
    }
    

    The EndRequest event in Global.asax may also be an option.

    public override void Init() {
        base.Init();
    
        EndRequest += MyEventHandler;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have controller X which inherits from controller Y: class X < YController
The title is very clear. I have an application-BaseController which inherits from Controller-class now.
I have a controller which inherits from an abstract secure controller which holds a
I have seen a nice example whereby the MVC controller class inherits from another
I have a Snake class, which has a pointer to a Controller class object.
I have a controller which has a method called history class UsersController < ApplicationController
I have a controller named BaseController that inherits from ApplicationController whitout a model associated
I have a subclassed UITableView, 'subclassChild' which inherits from another subclass 'subclassParent'. 'subclassParent' then
I have a parent class in rails that inherits from ActiveRecord::Base. I'm trying to
I have the following on my base controller class which my other controllers inherit

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.