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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Response.ContentType = "application/json";

or more generally

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

Method 2

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");


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x