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

我们只能通过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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....