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

查看:111
本文介绍了在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);

这篇关于在ASP.Net Core中获取HTTP状态代码描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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