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 3665088
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:43:09+00:00 2026-05-19T01:43:09+00:00

In order to support a legacy application that’s in the field, I need my

  • 0

In order to support a legacy application that’s in the field, I need my ASP.NET MVC app to return an empty response that also has a Content-Type. One of IIS, ASP.NET, or ASP.NET MVC is removing my Content-Type when I send back a null response. Is there any way around this?

(While not requiring an empty response with a set Content-Type would obviously be the ideal solution, the clients are already out there, and many of them cannot be upgraded.)

EDIT: Since there was a request for code: I’m proxying the request from the new web application to the one that older clients rely on. To do this, I have a subclass of ActionResult, called LegacyResult, that you can simply return for those methods that need to be handled by the old software. This is the relevant part of its code:

    public override void ExecuteResult(ControllerContext context)
    {
        using (var legacyResponse = GetLegacyResponse(context))
        {
            var clientResponse = context.HttpContext.Response;
            clientResponse.Buffer = false;
            clientResponse.ContentType = legacyResponse.ContentType; /* Yes, I checked that legacyResponse.ContentType is never string.IsNullOrEmpty */
            if (legacyResponse.ContentLength >= 0) clientResponse.AddHeader("Content-Length", legacyResponse.ContentLength.ToString());

            var legacyInput = legacyResponse.GetResponseStream();
            using (var clientOutput = clientResponse.OutputStream)
            {
                var rgb = new byte[32768];
                int cb;
                while ((cb = legacyInput.Read(rgb, 0, rgb.Length)) > 0)
                {
                    clientOutput.Write(rgb, 0, cb);
                }
                clientOutput.Flush();
            }
        }
    }

If legacyInput has data, then Content-Type is set appropriately. Otherwise, it’s not. I can actually kluge the old backend to send an empty v. non-empty response for exactly the same request, and observe the difference in Fiddler.

EDIT 2: Poking around with Reflector reveals that, if headers have not been written at the time that HttpResponse.Flush is called, then Flush writes out the headers itself. The problem is that it only writes out a tiny subset of the headers. One of the missing ones is Content-Type. So it seems that, if I can force headers out to the stream, I can avoid this problem.

  • 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-05-19T01:43:10+00:00Added an answer on May 19, 2026 at 1:43 am

    You have to trick the response into writing the headers, by falsely telling it there’s content, then suppressing it:

    /// [inside the writing block]
    var didWrite = false;
    while ((cb = legacyInput.Read(rgb, 0, rgb.Length)) > 0)
    {
      didWrite = true;
      clientOutput.Write(rgb, 0, cb);
    }
    if (!didWrite)
    {
      // The stream needs a non-zero content length to write the correct headers, but...
      clientResponse.AddHeader("Content-Length", "1");
      // ...this actually writes a "Content-Length: 0" header with the other headers.
      clientResponse.SuppressContent = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .NET WinForms app written in C#. In order to support batch
I would like to use ORDER BY FIELD() (MySQL) in Django. Does Django support
I have a Rails application that has to co-exist with a very old legacy
Currently I have a legacy based non-MVC php framework which I need to update
The Situation I need to support generating XML documents based on schemas that vary
I am writing a Google App Engine (Java) application that reads data from a
In order to support UIDocumentController options on different file types, I thought that perhaps
In order to support automated testing tools I need to x:Name all controls (so
I have an MFC application using satellites DLLs in order to support the multilingualism.
In my Application i use 54 images.in order to support multiple screen i create

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.