Matt
Matt

Reputation:

Creating a JSON Header on ASP.NET

I am converting a script from PHP to ASP.net C#. In PHP, i could use something like:

header('Content-type: text/json');

header('Content-type: application/json');

How can I tell my aspx page to declare in the header that it is printing a JSON file?

Upvotes: 17

Views: 50272

Answers (2)

David Duman
David Duman

Reputation: 6656

Additional info about JerSchneid's answer

If you got an error message like this:

This operation requires IIS integrated pipeline mode.

You can use this way:

Response.AddHeader("Content-type", "text/json");

Upvotes: 7

JerSchneid
JerSchneid

Reputation: 5917

Response.ContentType = "application/json";

or more generally

Response.Headers.Add("Content-type", "text/json");
Response.Headers.Add("Content-type", "application/json");

Upvotes: 43

Related Questions