views:

23

answers:

2

I have a fairly standard MVC2 app running on 4.0 and under IIS6. I took the wildcard filter approach to route all requests to the asp.net ISAPI filter. So far so good.

I have now added some code to Application_Error in the global.asax to trap exceptions and email me the stack, etc. This also works fine.

But, I am receiving all kinds of 404 related traffic. Mostly "The controller for path '/favicon.ico' was not found or does not implement IController" but I can imagine that I soon be receiving robot.txt requests etc.

Is there any way that I can get the HTTP Error Code from HttpContext.Current.Server.GetLastError()? I can then simply ignore all 404 results. Or is there a different approach that I should be looking at?

+2  A: 

Regarding the favicon, you can do this in Global.asax to add an ignore route:

routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
MartinHN
Nice approach but I was hoping for something a bit more generic. I think that can only be accomplished via 404 trapping.
Andrew Robinson
Probably. I think the main issue here is, that you're dismissing the Static File Handler, by sending everything to ASPNET_ISAPI.Can you download your images from your app?
MartinHN
A: 

Ask a question, find the answer....

I need to test this but it look promissing.

var ex = HttpContext.Current.Server.GetLastError();

// filter out 404 responses
var httpException = ex as HttpException;
if (httpException != null && httpException.GetHttpCode() == 404)
    return;
Andrew Robinson