Sergey Zhukov Sergey Zhukov - 17 days ago 6
C# Question

How to set StatusDescription from Kestrel server?

How to set HTTP status descrption from Kestrel Server? I want to return

HTTP/1.1 400 ArgumentException
instead of
HTTP/1.1 400 Bad Request
but can't find
StatusDescription
property in
DefaultHttpResponse
, I can only change
StatusCode
with numeric code.

Here is the sample App:

https://github.com/aspnet/KestrelHttpServer/tree/dev/samples/SampleApp

Answer

You need to access the HTTP context features to override the reason phrase, for example:

context.Response
    .HttpContext
    .Features
    .Get<IHttpResponseFeature>()
    .ReasonPhrase = "Stuff here";