在 ASP.Net Core 中获取 HTTP 状态码描述 [英] Get HTTP status code descriptions in ASP.Net Core
问题描述
在以前版本的 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:
ASP.Net Core 中是否有类似于 HttpWorkerRequest.GetStatusDescription
的东西?
Is there something similar to HttpWorkerRequest.GetStatusDescription
in ASP.Net Core?
推荐答案
您可以使用 Microsoft.AspNetCore.WebUtilities.ReasonPhrases.GetReasonPhrase(int statusCode)
(可以从 NuGet 中的 Microsoft.AspNetCore.WebUtilities 包 如果尚未在您的项目中被类似的包暂时引用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);
这篇关于在 ASP.Net Core 中获取 HTTP 状态码描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!