title: Set the reason on a HttpResponse in ASP.NET Core from middlware
body: <p>How can I set the reason phrase on a HTTP response in ASP.NET Core from some middleware?</p>
  
  <p>In previous versions (full framework), I would do the following:</p>
  
  <pre><code>context.Response.StatusCode = 401;
  context.Response.ReasonPhrase = "Missing or invalid token.";
  </code></pre>
  
  <p>In ASP.NET Core, the only property available is the <code>StatusCode</code>.</p>
  
  <p>Here is an example of a Fiddler capture with a custom reason set on the response.</p>
  
  <p><a href="https://i.stack.imgur.com/taXpC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/taXpC.png" alt="Example of a reason sent from ASP.NET WebAPI (full framework)"></a></p>