tags:

views:

110

answers:

1

I have an ASP.NET MVC site and ELMAH is showing me that my site is erroring when receiving an HTTP request with REQUEST_METHOD = HEAD.

How do I respond to these requests using ASP.NET MVC?

+1  A: 

Use the [AcceptVerbs( HttpVerbs.Head )] attribute to mark the method as responding to a HEAD request. You can add more potential methods by OR'ing the verbs together so it can respond to multiple request verbs. I suspect your method is already marked with the attribute as I think it should respond to any request verb if you don't have any restrictions. On a side note, I think it would be pretty rare to get a HEAD request, care to elaborate on why and how you're receiving it?

tvanfosson
Thanks. My home controller's index method is the one being hit with the HEAD request. It's currently set up with an AcceptVerbs(HttpVerbs.GET). I guess I'll need to add an HttpVerbs.Head to that as well. As for why I'm receiving the request, I wish I knew more myself. All I know is that I periodically get an error e-mail from ELMAH saying "A public action method 'Index' could not be found on controller 'Web.Controllers.HomeController'". The details show that the REQUEST_METHOD is HEAD. I don't recognize the IP address the request comes from. Maybe a spider/crawler?
Kevin Pang
I wouldn't add the verb unless **your code** is what is making the request. It may be that you want to respond to this request, but I would expect most spider/crawlers would be doing a full GET. FWIW, I don't see these when Google crawls my sites.
tvanfosson
I get this from web spiders too. Its a pain in the ass.
Schotime