3

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.

2 Answers 2

4

Just cast it to int :

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

Now codeAsInteger is 404.

Sign up to request clarification or add additional context in comments.

Comments

3

Cast it to an integer

(int)HttpStatusCode.NotFound

1 Comment

Thanks, I was really very easy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.