0

I'm working on an ASP.NET MVC 5 website hosted as an Azure website and I have included ELMAH for error logging. All seems to work fine except I find numerous errors like this one:

A public action method '...' was not found on controller ...

These errors appear mostly when the request comes from a spider bot but they don't seem to produce any errors in the response. Also, all logged controller/action names are totally valid.

E.g. when I run a tool like deadlinkchecker.com on my site, I find hundreds of errors in ELMAH while the tool produces a report with 100% valid links. The path info in ELMAH is also correct.

Why am I seeing these errors?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Koen
  • 3,626
  • 1
  • 34
  • 55
  • Depends on how your Error Handling works. Just because Elmah logs an error doesn't mean you aren't returning a status of 200 with a page that Says 404. Probably be easier to debug if you provide your error handling code. – Erik Philips Mar 31 '14 at 22:44
  • 1
    Are the actions marked as POST? The spider will only do GET requests – matt_lethargic Apr 01 '14 at 00:21
  • @ErikPhilips: There is no error handling code. It's all configured in web.config. system.web/customErrors + system.webServer/httpErrors + elmah/errorLog (xml). Also, if Elmah logs a controller/action mismatch like above, why does it work fine? – Koen Apr 01 '14 at 10:24
  • You are seeing those elmah errors because the clients are getting 404s. We used to get those in Elmah too, until I decided they were just noise and I turned them off in Elmah. I suggest you do the same https://code.google.com/p/elmah/wiki/ErrorFiltering#Filtering_Declaratively_via_Configuration – Nathan Apr 01 '14 at 19:56
  • @Nathan: It were not 404's (and I do like to see those to see if anyone maybe has incorrect references to my site). – Koen Apr 02 '14 at 09:14
  • @matt_lethargic: You are right. They are HEAD requests while I have annotated these actions with HttpGet attributes. – Koen Apr 02 '14 at 09:14

1 Answers1

2

If you add Head as well as Get then this error will go away and the spider will read your site correctly. As Nathan said, you could turn them off, but you're not fixing the issue really, just ignoring it and you might lose out if spiders cannot read your site 100%

This should work, get fiddler out and try it!

[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Head)]
public ActionResult Test()
{
    return View();
}
matt_lethargic
  • 2,706
  • 1
  • 18
  • 33
  • Is this the same as [HttpGet, HttpHead]? – Koen Apr 02 '14 at 14:26
  • 1
    Yes this is the same. I'm on my Mac at the moment (not Boot Camped right now) so can't test it sorry. (I normally like to test my answers first) – matt_lethargic Apr 02 '14 at 16:40
  • 1
    Apparently it is not the same (at least not in MVC5). [HttpGet, HttpHead] requires both verbs (and thus will respond to nothing). AcceptVerbs allows one of the listed verbs (flags logic). See also: http://stackoverflow.com/a/8354511/192961 – Koen Apr 03 '14 at 15:22