title: .NET Core Web API: return a custom HTTP status code with Content Type application/problem+json
body: <p><code>ControllerBase</code> contains methods such as <code>Conflict()</code> that return a <code>ConflictResult</code> object (representing an HTTP 409 response) that is derived from <code>StatusCodeResult</code>.  The resulting response body has content type <code>application/problem+json</code> and looks like this:</p>
  
  <pre><code>{
      "type": "https://tools.ietf.org/html/rfc7231#section-6.5.8",
      "title": "Conflict",
      "status": 409,
      "traceId": "0HLO99QHFC9QI:00000001"
  }
  </code></pre>
  
  <p>There is no in-built method/class for an HTTP 410 response, so I made one:</p>
  
  <pre><code>[DefaultStatusCode(410)]
  public class GoneResult : StatusCodeResult
  {
      public GoneResult() : base(410)
      {}
  }
  ...
  public static class ControllerBaseExtensions
  {
      public static GoneResult Gone(this ControllerBase controllerBase) // this doesn't give all the problem+JSON attributes
      {
          return new GoneResult();
      }
  }
  </code></pre>
  
  <p>However, this gives </p>
  
  <pre><code>{
      "type": "about:blank",
      "status": 410
  }
  </code></pre>
  
  <p>i.e., the <code>type</code> value is different and the <code>title</code> and <code>traceId</code> fields are missing.</p>
  
  <p>I'd also like to create a custom class for an HTTP 500 response that includes a <code>message</code> field with the error message.  I've tried returning <code>StatusCode(StatusCodes.Status500InternalServerError)</code>, which gives me the same minimal <code>application/problem+json</code> response as my <code>Gone()</code> method; I've also tried returning <code>StatusCode(StatusCodes.Status500InternalServerError, message)</code>, which gives me my error message but formats the response as <code>text/plain</code>.</p>