How to return JSON instead of XML in ASP.NET Web API when using Chrome ?

When using the ASP.NET Web API in Google Chrome , there are times when you see the XML output instead of JSON. You might want to request JSON data so that you can view it in the browser.

How to return JSON instead of XML in ASP.NET Web API when using Chrome ?

To get it to work , simply add the below code in the WebApiConfig.cs class in the App_Start folder of your ASP.NET WebAPI project.

 
config.Formatters.JsonFormatter.SupportedMediaTypes .
  Add(new MediaTypeHeaderValue("text/html") );

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

You can pass an array of integer to an ASP.NET Web Web API REST service by setting the [FromUri] attribute...
One of the common ways to refresh webpage every few mins is by using JavaScript or HTML Meta tag. For...
This post will provide the list of some of the top ASP.NET based Content Management Systems (CMS) that you may...