我们收到了许多HTTP HEAD方法请求,主要来自看似Twitter的机器人.默认的ASP.Net/MVC3响应是’500内部服务器错误’,正在被elmah和log4net捕获/记录(现已过滤掉!).
我可以根据这个问题编写一个特定的控制器和路由来处理这些非HTTPS请求 – Responding to HEAD Request in asp.NET MVC 3.
但是,从机器人的角度来看,最好的反应是什么呢? 200显示服务器是活动的,302重定向到HTTPS网址,还是坚持500,因为网站无法通过HTTP访问?
解决方法
405 Method Not Allowed@H_403_13@意思是
The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.
或者
501 Not Implemented@H_403_13@意思是
The server does not support the functionality required to fulfill the request. This is the appropriate response when the server does not recognize the request method and is not capable of supporting it for any resource.
就个人而言,我会选择405,因为它在客户端是一个错误,“嘿,我们不会在这里提供这些东西.”对我来说似乎比“你到底在说什么?我不理解它”.一,后者是由服务器建议不识别501描述的请求方法位.
所有HTTP状态代码:http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html