在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)
(可从(如果尚未在项目中由 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屋!