ASP.NET MVC3 – 您如何处理探测请求?

我们的网站上线了,当然,我们开始收到大量的探测请求,
喜欢

‘/blog/wp-login.PHP
‘/admin/admin.PHP

等等
所以问题是,你用它们做什么?

现在在每种情况下都会抛出404错误并且elmah会发送有关它的电子邮件,但我认为最好至少忽略所有的PHP请求.

如何做到这一点,这样的请求将最低限度地加载服务器,可能是这样,asp.net管道将不参与此类请求?
或者重定向或返回空结果更好?

如果需要简单地添加IgnoreRoutes,可能有人有一套好的路由,这会忽略大多数探测请求?

解决方法

我知道你已经声明你不想在IIS中使用重写模块,因为它“在IIS上增加了额外的负载”,但事实上,使用IIS来处理这些将不会比传入你的应用程序那样密集.同样的事情(即使两者都是非常小的资源方面).如果您想在IIS和带宽上以最小的负载量忽略请求,我建议如下
<rewrite>
  <rules>
    <rule name="Fail PHP requests">
      <match url=".*"/>
      <conditions>
        <add input="{URL}" pattern="*.PHP*" />
      </conditions>
      <action type="AbortRequest" />
    </rule>
   </rules>
</rewrite>

使用设置为AbortRequest的操作类型进行的重写完全切断HTTP连接并删除请求,不返回404或403错误.摘自“创建访问块”部分中的Learn IIS.

编辑 – 由于OP对使用重写模块和性能存在担忧,我将提交第二个选项,它仍然可以在不使用重写模块的情况下捕获.PHP请求. IIS7及更高版本也支持请求过滤,根据Learn IIS,请求过滤是……

The request filtering module runs at the beginning of the request
processing pipeline by handling the BeginRequest event. The module
evaluates the request Metadata,such as headers,the query string,
content length,etc,in order to determine whether the request
Metadata matches any existing filter. If there is a match,the module
generates a 404 (File Not Found) response and then shortcuts the
remainder of the IIS pipeline

要实现,请将以下部分添加到web.config

<configuration>
 <system.webServer>
  <security>
   <requestfiltering>
    <fileExtensions allowUnlisted="true" >
     <add fileExtension=".PHP" allowed="false"/>
    </fileExtensions>
   </requestfiltering>
  </security>
 </system.webServer>
</configuration>

信息来自URL Rewrite vs Request FilteringUsing Request Filtering

相关文章

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