4

Yesterday, I set up Elmah to send me an email every time an unhandled exception is thrown that causes my website to crash.

This morning, I woke up and saw 6 emails with the exception:

"System.Web.HttpException: The controller for path '/none' was not found or does not implement IController."

They were from the Bing crawler bot. There was 2 more from Google and Yahoo crawler bots.

I've gone through my code and tested all my links on my web site and haven't found any errors. Nowhere do I try to route to a 'none' controller. The other 2 errors were similar but point to a couple other controllers but they work fine when I test them.

What am I doing wrong and how can I get rid of these errors?

I'm concerned that they will rank my website lower in search engines.

Update:

I was finally able to reproduce the errors. In my browser, I typed in: "www.mysite.com/abcde." My site's custom 404 error page showed which is good. However, Elmah generated an email saying

"The controller for path '/abcde' was not found or does not implement IController"

When I typed in: "www.mysite.com/Home/abcde", my custom 404 error page showed. Elmah then sent this email:

"A public action method 'abcde' was not found on controller 'MySite.Controllers.HomeController'."

This leads me to conclude that for some reason, the web crawler spiders are trying to access URLs on my site that have been removed or never existed.

How can I get elmah to not log errors that are coming from URLs that don't exist on my site? I don't want to get an email every time a visitor or web crawler tries to key in a URL that doesn't exist.

Also, is there a way to route the most common, invalid web crawler URLs like '/none' and '/error_log' to my main home page?

2 Answers2

4

After more research, I solved my problem.

Here are the steps:

  1. Create a class that implements the IExceptionFilter interface. Have the code check to see if the Exception was handled. If it was then signal Elmah.

    public class ElmahHandledErrorLoggerFilter : IExceptionFilter
    {
        public void OnException(ExceptionContext context)
        {
            if (context.ExceptionHandled)
                ErrorSignal.FromCurrentContext().Raise(context.Exception);
        }
    }
    
  2. Register a new instance of ElmahHandledErrorLoggerFilter in the GlobalFilterCollection list in the FilterConfig class. Note: This must be registered after the TransactionFilter object.

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new TransactionFilter());
        filters.Add(new ElmahHandledErrorLoggerFilter());
    }
    
  3. In the Globals.asax.cs file, add event handlers to filter out 404 exceptions.

        protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
        {
            FilterError404(e);
        }
    
        protected void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e)
        {
            FilterError404(e);
        }
    
        // Dismiss 404 errors for ELMAH
        private void FilterError404(ExceptionFilterEventArgs e)
        {
            if (e.Exception.GetBaseException() is HttpException)
            {
                HttpException ex = (HttpException)e.Exception.GetBaseException();
                if (ex.GetHttpCode() == 404)
                    e.Dismiss();
            }
        }
    

    That was it. Now 404 errors aren't logged or mailed but all other exceptions will be logged/mailed.

I'll periodically use Xenu to scan my website for broken links.

You can read more Here, Elmah Documentation and Stack Overflow.

Community
  • 1
  • 1
1

Most likely it means somewhere on your pages there is link to "none" - i.e. something that you consider script-only link (with click handler that cancels default nav). Fixing depend on what link actually supposed to do, but it is generally good idea for all links to point to existing locations even if it normally handled by script.

You may try to crawl your site yourself (either with basic code written with HTMLAgilityPack or existing site scanning tools) to check if there are links that does not point to correct places.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • OK Thanks. I signed up with a free website scanning service. As soon as they finish scanning my site, I'll post the results. – Peter Ringering Feb 01 '16 at 04:14
  • Would the search engine bots crawl my backend area? I've got it setup where you have to be an Admin to get into that area on my web site. It's the only area that has javascript code that responds to click events. – Peter Ringering Feb 01 '16 at 04:28
  • @PeterRingering Look at IIS logs (or whatever server you use to host your web site) to know what is/isn't crawled. – Alexei Levenkov Feb 01 '16 at 04:34
  • I'm using GoDaddy.com to host my web site, so I don't think I can access their IIS logs. I've updated my the question with the results of my latest research. Thanks for your help! – Peter Ringering Feb 01 '16 at 23:12
  • Also, I just ran a scan on my web site and it found no bad links. – Peter Ringering Feb 02 '16 at 05:17