I am trying to set a custom HTTP status header in an HTTP response. For instance:.
400 Why do you want to do that
I do this by setting StatusDescriptionfor HttpResponsein IHttpHandler, in
<%@ WebHandler Language="C#" Class="Foo" %>
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";
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; } }
}
But in the response headers from the server, the status bar does not contain what I told her to contain, and instead continues to contain the standard StatusDescription:
400 Bad Request


How to change the StatusDescriptionheader HttpResponsewhen in a common handler?
Bonus Chatter
There are three properties:
int StatusCode: 400String StatusDescription: Bad RequestString Status: 400 Bad Request
The setting StatusCodewill change the settings StatusDescriptionandStatus
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
It also works differently:
StatuCode StatusDescription Status
================== ========= ================= ====================
initial 200 OK 200 OK
StatusDescription="Brilliant";
200 Brilliant 200 Brilliant
StatusCode=451;
451 Brilliant 451 Brilliant
and vice versa
StatuCode StatusDescription Status
================== ========= ================= ====================
initial 200 OK 200 OK
Status="451 Brilliant"
451 Brilliant 451 Brilliant
Bonus Bonus Bonus
From RFC 2616 - Hypertext Transfer Protocol - HTTP / 1.1 :
6.1.1 Status Code and Phrase Reason
, HTTP/1.1, . - - , .