如何从Kestrel服务器设置StatusDescription?

时间:2016-10-14 10:20:47

标签: c# .net-core kestrel-http-server

如何从Kestrel Server设置HTTP状态描述?我想回来 HTTP/1.1 400 ArgumentException代替HTTP/1.1 400 Bad Request,但无法在StatusDescription中找到DefaultHttpResponse属性,我只能使用数字代码更改StatusCode

以下是示例App:

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

1 个答案:

答案 0 :(得分:4)

您需要访问HTTP上下文功能以覆盖原因短语,例如:

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