title: How do I configure the status code returned by my ASP.NET Web API service when the request has an unsupported Content-Type?
body: <p>If a request is made to my Web API service that has a <code>Content-Type</code> header containing a type not supported by that service, it returns a <code>500 Internal Server Error</code> status code with a message similar to the following:</p>
  
  <pre><code>{"Message":"An error has occurred.","ExceptionMessage":"No MediaTypeFormatter is available to read an object of type 'MyDto' from content with media type 'application/UnsupportedContentType'.","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)
     at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)
     at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)
     at System.Web.Http.ModelBinding.FormatterParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)
     at System.Web.Http.Controllers.HttpActionBinding.&lt;&gt;c__DisplayClass1.&lt;ExecuteBindingAsync&gt;b__0(HttpParameterBinding parameterBinder)
     at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
     at System.Threading.Tasks.TaskHelpers.IterateImpl(IEnumerator`1 enumerator, CancellationToken cancellationToken)"}
  </code></pre>
  
  <p>I would instead prefer to return a <code>415 Unsupported Media Type</code> status code as recommended, e.g, <a href="http://brockallen.com/2012/05/14/http-status-codes-for-rest/" rel="nofollow">here</a>.</p>
  
  <p>How do I configure my service to do this?</p>