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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:16:42+00:00 2026-05-26T09:16:42+00:00

Executive Summary context.Response.Header.Add("Content-Type", "application/json"); gets ignored while context.Response.ContentType = "application/json"; breaks jQuery ajax calls.

  • 0

Executive Summary

context.Response.Header.Add("Content-Type", "application/json");

gets ignored while

context.Response.ContentType = "application/json";

breaks jQuery ajax calls.

====================================================================

I have an IHttpHandler that returns some JSON data and is defined as:

void ProcessRequest(HttpContext context)
{
    context.Response.Write(/* some JSON */);
}

and called using the jQuery Ajax methods like so:

$.get(SOME_URL, SUCCESS);

This works fine.

However, if the ProcessRequest method is defined thus:

void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "application/json"
    context.Response.Write(/* some JSON */);
}

it fails, meaning that the SUCCESS function in $.get(SOME_URL, SUCCESS); never fires, yet the correct content still get returned with the expected headers according to Fiddler2.

On the other hand, if the ProcessRequest method is defined thus:

void ProcessRequest(HttpContext context)
{
    context.Response.Header.Add("Content-Type", "application/json");
    context.Response.Write(/* some JSON */);
}

everything works but Fiddler2 reports that it is being returned as type "text/html".

Any idea why that happens?

NOTE: The URL is extensionless and the application is running on IIS 7.5 so I wonder whether or not the problem is related to the IIS MIME types.

  • 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-26T09:16:42+00:00Added an answer on May 26, 2026 at 9:16 am

    An IHttpHandler is an excellent choice for implementing AJAX handlers in ASP.net. It has lower overhead than a page and is easy to setup/install compared to something like WCF web services. While you could make a classic .asmx webservice, this should have no effect on the problem you posted.

    Also context.Response.ContentType = “application/json”; is the correct technique for changing the contenttype header of the HttpResponse from inside the ProcessRequest method of your handler.

    Your problem will likely be a malformed response. The question is now to narrow down what is breaking the response.

    1. If you have not already done so, grab a full copy the server response using firebug, chrome developer tools, fiddler or wireshark. Using the correct technique for changing the content type highlighted above you say the ajax success event never fires, but you did not let us know if you inspected the HttpResponse for content type header, response code and valid json.
    2. Verify that the content type header was in fact set to “application/json”.
    3. Double check that your json is in fact syntactically correct as sent
      over the wire. (Remember this must be “evaluate-able” by JavaScript

      • a misplaced bracket, quote or colon can really muck it up).
    4. Do you have any control characters or unicode text in your json? Are
      they properly escaped? This is a common pitfall with json,
      improperly escaped content or incorrect encoding. Are you using any
      code to convert from bytes to strings or string to bytes in your
      code? If so, be sure you are using the desired encoding, probably
      utf-8.

    If you suspect that your chosen UrlRewriter technique is changing the response headers, I would hope this is relatively easy to turn off and test with an extension based URL to your handler? This would at least confirm that you are diagnosing the correct issue and that it is worth your time to further research the issue. If you confirm that the UrlRewriter is the problem, you should post a question about the specific UrlRewriter technology you are using. For example are you using something like Helicon Tech’s ISAPI Reqwrite? Or Microsoft’s new URL Rewriter? Your own proprietary solution?

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

Sidebar

Related Questions

Executive Summary: When assertion errors are thrown in the threads, the unit test doesn't
Executive summary: how do I install a new root certificate into Java using Java
Executive summary: I need a way to determine whether a Windows process I've spawned
Executive Summary: preg_replace() ran faster than string comparisons. Why? Shouldn't regular expressions be slower?
Summary: I periodically get a .NET Fatal Execution Engine Error on an application which
Executive summary: How can I define an arbitrarily-sized 2D array in C? How can
Quick summary: I'm making an application that parses a binary file, stores vertices and
What is the default content returned when accept header is empty? The below code
Executive summary: *Improve the memory efficiency of the date-based extraction functions used in aggregate
Below is the usual Program.cs content for a windows service program: static class Program

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.