views:

745

answers:

2

I'm trying to create some basic logging for unhandled exceptions in my ASP.NET MVC application, but as I'm using IIS6 all requests come through .NET. Now while I agree that missing images are an important thing to flag, they aren't show-stoppers and so I'd like to set the event priority to high for 404s unless they are images (which will get medium priority).

The problem is that in Application_OnError the Response.StatusCode is 200, but the final result sent out is 404. To this end, I don't seem to be able to watch out for 404s to set the appropriate priority.

Is there a way to tell what the StatusCode is going to be?

A: 

You would have to send all traffic through to the .net isapi layer and do a manual 404 check yourself (if file exists) I would imagine

tigermain
+3  A: 

You can get it via Context.Server.GetLastError():

if ((Context.Server.GetLastError() is HttpException) && ((Context.Server.GetLastError() as HttpException).GetHttpCode() == 404))
{
    // do something
}
veggerby
This is the correct answer : it worked for me before it was posted here :)
Andrei Rinea