constants for http status codes

A

Andy Fish

Hi,

I've RTFM'd in vain for some named constants in the asp.net framework
representing the HTTP error codes - the equivalent of Java's
HttpServletResponse.SC_NOT_FOUND for 404 etc.

All the examples I've seen just use numbers. Anyone seen proper constant
definitions for these?

Andy
 
J

John Timney \(ASP.NET MVP\)

The httpWebResponse object has a statusCode property

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
A

Andy Fish

Thanks, that's (almost) what I was looking for.

It seems a bit strange to go to all the trouble of defining an enum and then
have HttpException.GetHttpCode() return an int instead.

Still, by casting the HttpStatusCode to an int, I achieved the desired
result.
 
J

Juan T. Llibre

The Reason-Phrase constants are not needed for
programming puprposes, according to rfc2616 :

http://www.rfc-editor.org/rfc/rfc2616.txt

"The Reason-Phrase is intended to give a short textual
description of the Status-Code. The Status-Code is
intended for use by automata and the Reason-Phrase
is intended for the human user."

The System.web.HttpResponse.StatusCode method
allows you to program against the Status Code numbers.

Search that document for "The first digit of the Status-Code"
to see a complete description for each Status Code
and their Reason-Phrases.
 
A

Andy Fish

Agreed, but I wasn't talking about processing the reason phrase. I was
talking about having a named constant used to represent to the integer
status code value, rather than putting the number 404 in my code all over
the place.
 
J

Juan T. Llibre

Hi, Andy.

Thanks for clarifying.

I suppose that the reason for using integer status code values,
as opposed to using named constants, would have to do with
terseness of code ( less verbosity ).

SC_NOT_FOUND is much more verbose than 404.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top