constants for http status codes

  • Thread starter Thread starter Andy Fish
  • Start date Start date
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
 
The httpWebResponse object has a statusCode property

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
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.
 
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.




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
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.
 
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.




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
Back
Top