我正在.NET Core MVC ActionFilter中执行以下操作,以返回禁止状态代码:
public override void OnActionExecuting(ActionExecutingContext context)
{
context.Result = new ContentResult()
{
StatusCode = (int)HttpStatusCode.Forbidden,
Content = "Token header is missing",
ContentType = "text/plain",
};
return;
}
这可以正常工作,但是我还要设置“ ReasonPhrase”,它可以从调用HttpClient.SendAsync方法返回的“ HttpResponseMessage”类中找到。如何从ActionFilter设置ReasonPhrase?