Get HTTP status code descriptions in ASP.Net Core

后端 未结 4 1836

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

Get description for HTTP status code

Is the

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-19 04:40

    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);
    

提交回复
热议问题