简体   繁体   中英

Increase maximum size of POST or PUT request to Kentico REST services over 64KB

Using Kentico 10, we're having issues raising the maximum request limit size above the default 64KB limit for any requests that go to the [servername]/rest/ services. All POST or PUT requests over that limit are met with server error 413 - request entity too large. In other parts of the application (such as the Kentico Admin) this limit does not exist as we're able to send POST and PUT requests with much higher amounts of data.

We've tried adding the following configuration to our web.config file but this does not affect the 64KB limit:

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

In addition, we've added a location element to the web.config with the following settings:

<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>

Neither of the configuration changes above had any affect on the POST or PUT requests over 64KB.

Kentico routes any requests to [servername]/rest/... through their URLRewritingEngine and rewrites those requests to DocumentRESTService.svc, ObjectTranslationRESTService.svc, or RESTService.svc depending on the type of call. So adding configuration sections to the system.serviceModel doesn't affect the use of those services.

How can we change this limit for the Kentico web services?

This can be done by adding the following pieces of code into the <system.serviceModel> section at the end of the web.config file:

Insert a <webHttpBinding> element into the <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>

Add a <service> element under the <services> 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>

https://docs.kentico.com/k10/integrating-3rd-party-systems/kentico-rest-service/configuring-the-rest-service#ConfiguringtheRESTservice-Enablinguploadoflargedata

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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