如何从HttpStatusCode的对象获取HTTP状态代码id(在ASP.NET中? 例如,我得到“HttpStatusCode.NotFound”我想得到错误代码404.
答案 0 :(得分:4)
只需将其投放到int
:
HttpStatusCode statusCode = HttpStatusCode.NotFound;
int codeAsInteger = (int)statusCode;
现在codeAsInteger
是404
。
答案 1 :(得分:3)
将其转换为整数
(int)HttpStatusCode.NotFound