
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Handling Web Server Errors
|
799
else if((statusCode >= 200)&& (statusCode <= 299))
{
return ResponseCategories.Success;
}
else if((statusCode >= 300)&& (statusCode <= 399))
{
return ResponseCategories.Redirected;
}
else if((statusCode >= 400)&& (statusCode <= 499))
{
return ResponseCategories.ClientError;
}
else if((statusCode >= 500)&& (statusCode <= 599))
{
return ResponseCategories.ServerError;
}
return ResponseCategories.Unknown;
}
The ResponseCategories enumeration is defined like this:
public enum ResponseCategories
{
Unknown = 0, // Unknown code ( < 100 or > 599)
Informational = 1, // Informational codes (100 <= 199)
Success = 2, // Success codes (200 <= 299)
Redirected = 3, // Redirection code (300 <= 399)
ClientError = 4, // Client error code (400 <= 499)
ServerError = 5 // Server error code (500 <= 599)
}
Discussion
There are five different categories of status codes on an HTTP response, as shown in
Table 14-1.
Each of the status codes defined by Microsoft in the .NET Framework is assigned an
enumeration value in the
HttpStatusCode enumeration. These status codes reflect
what can happen when a request is submitted. The web server is free to return a sta-
tus code in the available range, even if it is not currently defined for most commer-
cial web servers. The defined status ...