title: How to set HttpResponse StatusDescription in a content handler?
body: <p>I am trying to set a custom HTTP status header in an HTTP response. E.g.:</p>
  
  <pre><code>400 Why do you want to do that
  </code></pre>
  
  <p>I am doing this by setting the <code>StatusDescription</code> of an <code>HttpResponse</code> in an <code>IHttpHandler</code>, in </p>
  
  <pre><code>&lt;%@ WebHandler Language="C#" Class="Foo" %&gt;
  
  using System;
  using System.Web;
  
  public class Foo : IHttpHandler
  {
  
      public void ProcessRequest(HttpContext context)
      {
          context.Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
          context.Response.StatusDescription = "Why do you want to do that";
  
              //Unnecessary; the string already contains this
          context.Response.Status = "400 Why do you want to do that";
  
          context.Response.ContentType = "text/plain";
          context.Response.Write("Hello World");
      }
  
      public bool IsReusable { get { return false; } }
  }
  </code></pre>
  
  <p>But in the response headers from the server the <em>status line</em> doesn't contain what i told it to contain, and instead continues to contain the default StatusDescription:</p>
  
  <pre><code>400 Bad Request
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/uBAdG.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/boKSj.png" alt="enter image description here"></p>
  
  <p>How do change the <code>StatusDescription</code> of an <code>HttpResponse</code> header when in a generic <em>handler</em>?</p>
  
  <h1>Bonus Chatter</h1>
  
  <p>There are three properties:</p>
  
  <ul>
  <li><strong><code>int StatusCode</code></strong>: <code>400</code></li>
  <li><strong><code>String StatusDescription</code></strong>: <code>Bad Request</code></li>
  <li><strong><code>String Status</code></strong>: <code>400 Bad Request</code></li>
  </ul>
  
  <p>Setting the <code>StatusCode</code> will alter the <code>StatusDescription</code> and <code>Status</code></p>
  
  <pre><code>                    StatuCode  StatusDescription  Status              
  ==================  =========  =================  ====================
  initial             200        OK                 200 OK
  StatusCode=400;
                      400        Bad Request        400 Bad Request
  StatusDescription = "Too much want";
                      400        Too much want      400 Too much want
  </code></pre>
  
  <p>It also works the other way:</p>
  
  <pre><code>                    StatuCode  StatusDescription  Status              
  ==================  =========  =================  ====================
  initial             200        OK                 200 OK
  StatusDescription="Brilliant";
                      200        Brilliant          200 Brilliant
  StatusCode=451;
                      451        Brilliant          451 Brilliant
  </code></pre>
  
  <p>and the other way</p>
  
  <pre><code>                    StatuCode  StatusDescription  Status              
  ==================  =========  =================  ====================
  initial             200        OK                 200 OK
  Status="451 Brilliant"
                      451        Brilliant          451 Brilliant
  </code></pre>
  
  <h1>Bonus Bonus Chatter</h1>
  
  <p>From <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1" rel="nofollow noreferrer">RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1</a>:</p>
  
  <blockquote>
    <p><strong>6.1.1 Status Code and Reason Phrase</strong></p>
    
    <p>The individual values of the numeric status codes defined for HTTP/1.1, and an example set of corresponding Reason-Phrase's, are presented below. The reason phrases listed here are only recommendations -- they MAY be replaced by local equivalents without affecting the protocol.</p>
  </blockquote>