10 Feb

Remove or Disable XML Formatter in ASP.NET WEB API

Remove XML Formatter in ASP.NET WEB API

In this post we can learn how to remove the default xml formatter in ASP.NET Web API. By default ASP.NET Web API returns XML output.

Write the following code in the App_Start/WebApiConfig.cs

public static class WebApiConfig
{
 public static void Register(HttpConfiguration config)
 {
   //Remove the XM Formatter from the web api
   config.Formatters.Remove(config.Formatters.XmlFormatter);

   config.MapHttpAttributeRoutes();
   config.Routes.MapHttpRoute(
   name: "DefaultApi",
   routeTemplate: "api/{controller}/{id}",
   defaults: new { id = RouteParameter.Optional }
   );
  }
}

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>