How can I get IIS wildcard code from an exception?

I handle exceptions with an HttpModule in a way like this:

 int errorCode = 500; HttpApplication httpApp = (HttpApplication)sender; try { if (httpApp.Server != null) { Exception ex; for (ex = httpApp.Server.GetLastError(); ex != null; ex = ex.InnerException) { try { HttpException httpEx = ex as HttpException; if (httpEx != null) errorCode = httpEx.GetHttpCode(); // ... retrieve appropriate content based on errorCode } catch { } } } 

For HTTP status codes (ex: 302, 404, 503, etc.) everything works fine. However, for IIS status codes (for example: 401.5, 403.4, etc.), can GetHttpCode extract them since its return value is an integer?

+6
source share
2 answers

You may not be able to. See the second-last answer here: http://www.velocityreviews.com/forums/t73739-sending-status-as-4011.html . HTTP RFC does not detect subcodes ( http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html ). It looks like it can only be MS - see the last answer in the first link, which then points to this: http://msdn.microsoft.com/en-us/library/system.web.httpresponse.substatuscode.aspx . Although it is precisely in order to set the code to a subcategory, and not to extract it, I am interested in the fact that it is supported only "with integrated pipeline mode in IIS 7.0 and, at least, with the .NET Framework version 3.0".

The only thing I can think of is to take a look at HRESULT in the ErrorCode property of the HttpException and see if something is happening at the bit level where you can find the code and subcode from this.

I don't know if that helps.

+2
source share

You do not want an internal exception. Do you want to:

 HttpException httpEx = httpApp.Server.GetLastError() as HttpException; if (httpEx != null) errorcode = httpEx == null ? 0 : httpex.GetHttpCode(); 
-2
source share

All Articles