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

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

You May Also Like

You can read connection string from web.config file in ASP.NET by using the ConfigurationManager class in case you want to...
When you deploy your ASP.NET Web Application on Windows Server running IIS , there are times that you might receive...
This post will explain how to resolve the error “Handler “aspNetCore” has a bad module “AspNetCoreModuleV2” in its module list”...