如何从ActionFilter(.NET Core)返回响应中的ReasonPhrase

时间:2019-03-20 16:03:06

标签: http asp.net-core asp.net-core-mvc action-filter

我正在.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?

0 个答案:

没有答案