ASP.NET MVC3 - 你如何处理探测请求?

标签 asp.net asp.net-mvc asp.net-mvc-3 iis-7

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


'/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在“创建访问 block ”部分。

编辑 - 由于 OP 对使用重写模块和性能存在担忧,我将提交第二个选项,该选项可能仍会在不使用重写模块的情况下捕获 .php 请求。 IIS7 及更高版本也支持请求过滤,根据学习 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 Filtering 的信息和 Using Request Filtering

关于ASP.NET MVC3 - 你如何处理探测请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8118703/

相关文章:

asp.net - 您将如何将 ASP.Net MVC 添加到现有的网站项目中?

asp.net - Ninject owin 依赖项到 IIS Web 主机中以实现 ASP.net Identity

c# - 不可变集合?

c# - ASP.NET MVC 5 中的 Azure AD 身份验证

asp.net-mvc - 如何使用 Sitecore MVC 设置 Ioc (Autofac)

asp.net-mvc - 自定义授权属性

asp.net-mvc-3 - 在 ASP.NET MVC3 的 Web 网格中使用 List<string> 作为模型

c# - 使用 ComponentModel.DataAnnotations 对英国日期格式进行 MVC3 验证(也使用 jquery ui datepicker)

jquery - Ajax 调用状态无法加载资源。简单的 ASP.NET 联系人类

ASP.Net MVC MvcBuildViews大大增加了编译时间