在ASP.Net Core中获取HTTP状态代码描述

问题描述:

在以前的ASP.Net版本中,我们可以通过以下几种方式检索HTTP状态代码的描述:

In previous versions of ASP.Net, we could retrieve the description of a HTTP status code in a few ways as shown here:

获取HTTP状态代码的说明

是在ASP.Net Core中是否有类似于 HttpWorkerRequest.GetStatusDescription 的东西?

Is there something similar to HttpWorkerRequest.GetStatusDescription in ASP.Net Core?

您可以使用 Microsoft.AspNetCore.WebUtilities.ReasonPhrases.GetReasonPhrase(int statusCode) (可从(如果尚未在项目中由 Microsoft这样的包临时引用)。 AspNetCore.App ):

You can use Microsoft.AspNetCore.WebUtilities.ReasonPhrases.GetReasonPhrase(int statusCode) (which can be got from the Microsoft.AspNetCore.WebUtilities package in NuGet if not already referenced in your project transiently by a package like Microsoft.AspNetCore.App):

using Microsoft.AspNetCore.WebUtilities;

int statusCode = 404;
string reasonPhrase = ReasonPhrases.GetReasonPhrase(statusCode);