简体   繁体   English

IIS可以设置为阻止超过特定限制的API响应吗?

[英]Can IIS be set up to block API Responses over a certain limit?

We have an application that acts as an API Gateway, taking calls and routing them through to other APIs and then relaying the responses. 我们有一个充当API网关的应用程序,接听电话并将它们路由到其他API,然后转发响应。

In our set up, we make sure that developers making API calls don't try and flood us by uploading massive files or sending in excessive JSON payloads. 在我们的设置中,我们确保开发API调用的开发人员不会通过上传大量文件或发送过多的JSON有效负载来淹没我们。 We're now trying to figure out how we make sure that we don't flood them in return if they make an API call that returns too much data. 我们现在正试图弄清楚如果他们进行返回过多数据的API调用,我们如何确保不会使它们泛滥。

Is there a way to set up either IIS or an ASP.Net app to refuses API responses over a certain size in the same way that we would refuse an API Request over a certain size? 有没有办法设置IIS或ASP.Net应用程序拒绝超过一定大小的API响应,就像我们拒绝超过一定规模的API请求一样?

Just to add an example in clear terms: 只是用明确的术语添加一个例子:

If a developer makes an API request to get all of their customers, the API Gateway passes that request to our internal Customers API. 如果开发人员发出API请求以获取其所有客户,则API Gateway会将该请求传递给我们的内部Customers API。 If the Customers API responds with a 600MB response, we want to block the response at the API Gateway and then we'll send a response to the developer asking them to change their request to reduce the resultset. 如果Customers API响应600MB响应,我们希望阻止API网关的响应,然后我们将向开发人员发送响应,要求他们更改其请求以减少结果集。

The response has not limit the size. 响应没有限制大小。 We can limit the response size by add more parameter Content-Length into the response header. 我们可以通过在响应头中添加更多参数Content-Length来限制响应大小。

to set Request limit you could set in web.config file: 设置您可以在web.config文件中设置的请求限制:

    <system.web>
<httpRuntime maxRequestLength="2147483647" />

or 要么

 <system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="2147483648" />
    </requestFiltering>
  </security>
</system.webServer>

Or 要么

You could also set below code in web.config: 您还可以在web.config中设置以下代码:

<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="50000000"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration> 

maxJsonLength Configures the maximum length of the JSON string. maxJsonLength配置JSON字符串的最大长度。

For more detail, you could refer: jsonSerialization Element (ASP.NET Settings Schema) 有关更多详细信息,请参阅: jsonSerialization元素(ASP.NET设置架构)

Regards, jalpa 问候,jalpa

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM