Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official Blog - Professional ASP.NET

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


Join me at CodeStock
HttpStatusCode – An Enumeration For the Web

I have posted before about IIS Status codes, realize that is not exactly a correct name for them, it should be Http Status Codes. I wanted to point you to a valuable enumeration in the System.Net namespace, HttpStatusCode. It contains members for each of the codes specific in RFC 2616 for HTTP 1.1, see page 57-71 or Section 10.

The HttpStatusCode enumeration should make it easier for .NET programmers to just program instead of looking up specific codes. One nice feature is the HttpWebResponse class has a Status property that implements the HttpStatusCode enumeration to do comparisons. This is really nice because it makes it pretty easy for a programmer to write a select case or switch statement (or an if statement if it warrants) to quickly route processing of the transaction based on the returned status code.

If myHttpWebResponse.StatusCode = HttpStatusCode.OK Then
    Console.WriteLine(ControlChars.Lf + ControlChars.NewLine + "Response Status Code is OK and StatusDescription is: {0}", myHttpWebResponse.StatusDescription)
End If

 

Share this post :
Posted: Thursday, June 26, 2008 5:37 PM

by Chris Love

Comments

Guy Harwood said:

thats useful, thanks.
# June 27, 2008 4:57 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS