HTTP状态码(HTTP status code)

如何从HttpStatusCode的对象(在ASP.NET中)获取HTTP状态代码ID例如,我得到“HttpStatusCode.NotFound”我想获得错误代码404。

How to get HTTP status code id from object of HttpStatusCode (in ASP.NET? For example I get "HttpStatusCode.NotFound" I would like get error code 404.

最满意答案

只需将其转换为int :

HttpStatusCode statusCode = HttpStatusCode.NotFound; int codeAsInteger = (int)statusCode;

现在codeAsInteger是404 。

Just cast it to int :

HttpStatusCode statusCode = HttpStatusCode.NotFound; int codeAsInteger = (int)statusCode;

Now codeAsInteger is 404.

更多推荐