1

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?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
tags2k
  • 82,117
  • 31
  • 79
  • 106

2 Answers2

6

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

if ((Context.Server.GetLastError() is HttpException) && ((Context.Server.GetLastError() as HttpException).GetHttpCode() == 404))
{
    // do something
}
BartoszKP
  • 34,786
  • 15
  • 102
  • 130
veggerby
  • 8,940
  • 2
  • 34
  • 43
0

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

Anthony Main
  • 6,039
  • 12
  • 64
  • 89