增加 POST 的最大大小或对 Kentico REST 服务的 PUT 请求超过 64KB
Increase maximum size of POST or PUT request to Kentico REST services over 64KB
使用 Kentico 10,我们在将发送到 [servername]/rest/ 服务的任何请求的最大请求限制大小提高到超过默认 64KB 限制时遇到了问题。所有超过该限制的 POST 或 PUT 请求都会遇到服务器错误 413 - 请求实体太大。在应用程序的其他部分(例如 Kentico Admin),此限制不存在,因为我们能够发送 POST 和 PUT 请求,其中包含更多数据。
我们已尝试将以下配置添加到我们的 web.config 文件中,但这不会影响 64KB 的限制:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2097151" />
</requestFiltering>
</security>
</system.webServer>
此外,我们还使用以下设置向 web.config 添加了位置元素:
<location path="rest">
<system.web>
<httpRuntime executionTimeout="2400" maxRequestLength="2097151" />
</system.web>
<system.webServer>
<serverRuntime uploadReadAheadSize="2000000000" maxRequestEntityAllowed="32000000" />
<security>
<requestFiltering>
<fileExtensions allowUnlisted="true" />
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
</system.webServer>
</location>
以上配置更改均未对超过 64KB 的 POST 或 PUT 请求产生任何影响。
Kentico 通过他们的 URLRewritingEngine 将任何请求路由到 [servername]/rest/... 并根据类型将这些请求重写到 DocumentRESTService.svc、ObjectTranslationRESTService.svc 或 RESTService.svc称呼。因此,向 system.serviceModel 添加配置部分不会影响这些服务的使用。
我们如何更改 Kentico 网络服务的此限制?
这可以通过将以下代码片段添加到 web.config 文件末尾的 <system.serviceModel>
部分来完成:
插入一个 <webHttpBinding>
元素到 <bindings>
sub-section:
<webHttpBinding>
<!-- Limits set to 10 MB (specified value in bytes) -->
<binding name="RESTQuotaBinding" maxReceivedMessageSize="10485760" maxBufferPoolSize="10485760" maxBufferSize="10485760" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
<readerQuotas maxDepth="32" maxStringContentLength="10485760" maxArrayLength="10485760" maxBytesPerRead="10485760" />
<security mode="None" />
</binding>
</webHttpBinding>
在<services>
下面添加一个<service>
元素 sub-section:
<service name="CMS.WebServices.RESTService">
<host>
<baseAddresses>
<add baseAddress="http://localhost/KenticoCMS/rest" />
</baseAddresses>
</host>
<endpoint address="" bindingConfiguration="RESTQuotaBinding" binding="webHttpBinding" contract="CMS.WebServices.IRESTService" />
</service>
使用 Kentico 10,我们在将发送到 [servername]/rest/ 服务的任何请求的最大请求限制大小提高到超过默认 64KB 限制时遇到了问题。所有超过该限制的 POST 或 PUT 请求都会遇到服务器错误 413 - 请求实体太大。在应用程序的其他部分(例如 Kentico Admin),此限制不存在,因为我们能够发送 POST 和 PUT 请求,其中包含更多数据。
我们已尝试将以下配置添加到我们的 web.config 文件中,但这不会影响 64KB 的限制:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2097151" />
</requestFiltering>
</security>
</system.webServer>
此外,我们还使用以下设置向 web.config 添加了位置元素:
<location path="rest">
<system.web>
<httpRuntime executionTimeout="2400" maxRequestLength="2097151" />
</system.web>
<system.webServer>
<serverRuntime uploadReadAheadSize="2000000000" maxRequestEntityAllowed="32000000" />
<security>
<requestFiltering>
<fileExtensions allowUnlisted="true" />
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
</system.webServer>
</location>
以上配置更改均未对超过 64KB 的 POST 或 PUT 请求产生任何影响。
Kentico 通过他们的 URLRewritingEngine 将任何请求路由到 [servername]/rest/... 并根据类型将这些请求重写到 DocumentRESTService.svc、ObjectTranslationRESTService.svc 或 RESTService.svc称呼。因此,向 system.serviceModel 添加配置部分不会影响这些服务的使用。
我们如何更改 Kentico 网络服务的此限制?
这可以通过将以下代码片段添加到 web.config 文件末尾的 <system.serviceModel>
部分来完成:
插入一个 <webHttpBinding>
元素到 <bindings>
sub-section:
<webHttpBinding>
<!-- Limits set to 10 MB (specified value in bytes) -->
<binding name="RESTQuotaBinding" maxReceivedMessageSize="10485760" maxBufferPoolSize="10485760" maxBufferSize="10485760" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
<readerQuotas maxDepth="32" maxStringContentLength="10485760" maxArrayLength="10485760" maxBytesPerRead="10485760" />
<security mode="None" />
</binding>
</webHttpBinding>
在<services>
下面添加一个<service>
元素 sub-section:
<service name="CMS.WebServices.RESTService">
<host>
<baseAddresses>
<add baseAddress="http://localhost/KenticoCMS/rest" />
</baseAddresses>
</host>
<endpoint address="" bindingConfiguration="RESTQuotaBinding" binding="webHttpBinding" contract="CMS.WebServices.IRESTService" />
</service>