Ich Ausnahmen mit einem HttpModule
in einer Art und Weise, wie diese Handhabung:Wie kann ich den IIS-Substatuscode von einer Exception abrufen?
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 { }
}
}
Für HTTP status codes (ex: 302, 404, 503, etc.) alles funktioniert super. Jedoch für IIS status codes (ex: 401.5, 403.4, usw.), kann GetHttpCode
diese abrufen, da sein Rückgabewert eine ganze Zahl ist?
+1. Ich mag das ** for ** Schleife ** Idee mit der ** InnerException **. Haben Sie jemals ein wenig Code gefunden, um diese IIS-Fehlercodes zu ziehen? – jp2code
FYI: Ihr Code hat es versäumt, irgendeinen Aufruf von 'Server.ClearError() anzuzeigen;' Wenn das nicht drin ist, sollten Sie es hinzufügen. – jp2code