加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-3 – 在仅HTTPS站点上对HTTP HEAD请求的正确响应

发布时间:2020-12-16 04:26:43 所属栏目:asp.Net 来源:网络整理
导读:我们只能通过HTTPS访问ASP.Net MVC3站点,方法是使用控制器上的RequireHTTPS属性. 我们收到了许多HTTP HEAD方法请求,主要来自看似Twitter的机器人.默认的ASP.Net/MVC3响应是’500内部服务器错误’,正在被elmah和log4net捕获/记录(现已过滤掉!). 我可以根据这
我们只能通过HTTPS访问ASP.Net MVC3站点,方法是使用控制器上的RequireHTTPS属性.

我们收到了许多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

意思是

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

意思是

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读