IIS 8 block request by JSON payload fields

时间:2015-06-26 10:20:27

标签: json asp.net-mvc iis payload

I have an MVC.NET 4 web server that accepts HTTP POST request with a JSON formatted string as the request data. I would like to add a rule in the IIS level before the request hits the server, to block request by some regex on that JSON string. Is that possible?

2 个答案:

答案 0 :(得分:5)

既然你说:

  

我希望它在IIS级别中以消除更多的Web负载   服务器级别需要为每个请求创建另一个线程。该   我想阻止一些请求的原因是它们与之无关   我的应用程序了,高负荷,我不能阻止它们   客户方

您有两个选择:

  1. 请求过滤
  2. 网址重写
  3. 请仔细阅读IIS 7.0 Request Filtering and URL Rewriting文章,了解最重要的事项。如果您的选择是第一个具有最高优先级的选项,<denyQueryStringSequences>在涵盖某些过滤要求的情况下会很有用。要使用 regex ,您需要使用第二个。以下示例规则可以停止在<rewrite>

    下处理请求
    <rule name="Block Bad Request Strings" stopProcessing="true">
         <match url=".*" />
         <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
              <add input="{QUERY_STRING}" pattern="id=([^\"]*[^-]?>)|(?:[^\\w\\s]\\s*\\\/>)|(?:>\") />
         </conditions>
         <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission" />
    </rule>
    

    有关详细信息,请参阅URL Rewrite Module Configuration Reference

答案 1 :(得分:2)

我认为创建和添加自定义Http Module可以解决您的问题。每个请求都会调用HTTP模块以响应BeginRequestEndRequest事件。