开发者

Global.asax Exception Handling and HTTP Error Codes

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开发者_JAVA技巧 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?


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

routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜