ASP.NET throws HttpException for numerous types of errors, making it difficult to determine exactly what went wrong programmatically. You can parse the error message, but the message can be localized, and therefore parsing it can be non-trivial. There is, however, a way that you can identify a few specific types of errors.
In v2.0 there is an internal property on HttpException named WebEventCode that returns an int. This value contains additional information which you can use to determine the type of error. Because it is internal you will have to use private reflection to get the value, but the property has been made public in v4.0. Below I've listed the meaning of several of the possible values of this property:
- If the HttpException is because the request timed out ("Request timed out."), the value will be System.Web.Management.WebEventCodes.RuntimeErrorRequestAbort.
- If it's because the client posted too much data ("Maximum request length exceeded."), the value will be WebEventCodes.RuntimeErrorPostTooLarge.
- If it's caused by a ViewState error, the value will be WebEventCodes.RuntimeErrorViewStateFailure.
Again, this property has been made public in v4.0, but for v2.0, you'll have to use private reflection to access it.