在 ASP.Net Core 中获取 HTTP 状态码描述 [英] Get HTTP status code descriptions in ASP.Net Core

查看:43
本文介绍了在 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)(可以从 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆