JSON 限制为 1180 个字符
JSON Limited to 1180 Characters
我有一个简单的 JavaScript JSON 请求,它是一个通过 JSON 请求发送到我的 C# Web 服务器的对象。
只要 stringy 返回的字符串超过 1180 个字符,就不会在服务器上调用 WebMethod。
据我了解,客户端可以通过 JSON 发送的字符串数据量没有限制。我知道限制在服务器端,试图接受参数化请求。
web.config 中有什么地方可以提高 1180 的限制吗?
我当前的配置;
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=aspnetdb" providerName="System.Data.SqlClient"/>
<add name="ApplicationServices2" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=trimweb" providerName="System.Data.SqlClient"/>
<add name="ApplicationServices3" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=Customers" providerName="System.Data.SqlClient"/>
<add name="ApplicationServices4" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=OrderUpdate;User ID=test1;Password=test1;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<behaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<services>
<service name="ServiceSite.CustomersService">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="webHttpBindingWithJsonP" contract="ServiceSite.CustomersService"
behaviorConfiguration="webHttpBehavior"/>
</service>
</services>
</system.serviceModel>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
您需要将 webHttpBinding
更改为如下所示:
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000"/>
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
</webHttpBinding>
See the docs for <webHttpBinding>
here
注意: 在 ASP.NET 兼容模式下,仅增加此值是不够的。您还应该增加 httpRuntime 的值(参见 httpRuntime)。
这应该是这样的:
<httpRuntime
maxQueryStringLength = "2048"
maxRequestLength="4096"
maxUrlLength = "260"
requestLengthDiskThreshold="80"/>
(根据需要增加数量)
我有一个简单的 JavaScript JSON 请求,它是一个通过 JSON 请求发送到我的 C# Web 服务器的对象。
只要 stringy 返回的字符串超过 1180 个字符,就不会在服务器上调用 WebMethod。
据我了解,客户端可以通过 JSON 发送的字符串数据量没有限制。我知道限制在服务器端,试图接受参数化请求。
web.config 中有什么地方可以提高 1180 的限制吗?
我当前的配置;
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=aspnetdb" providerName="System.Data.SqlClient"/>
<add name="ApplicationServices2" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=trimweb" providerName="System.Data.SqlClient"/>
<add name="ApplicationServices3" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=Customers" providerName="System.Data.SqlClient"/>
<add name="ApplicationServices4" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=OrderUpdate;User ID=test1;Password=test1;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<behaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<services>
<service name="ServiceSite.CustomersService">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="webHttpBindingWithJsonP" contract="ServiceSite.CustomersService"
behaviorConfiguration="webHttpBehavior"/>
</service>
</services>
</system.serviceModel>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
您需要将 webHttpBinding
更改为如下所示:
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000"/>
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
</webHttpBinding>
See the docs for <webHttpBinding>
here
注意: 在 ASP.NET 兼容模式下,仅增加此值是不够的。您还应该增加 httpRuntime 的值(参见 httpRuntime)。
这应该是这样的:
<httpRuntime
maxQueryStringLength = "2048"
maxRequestLength="4096"
maxUrlLength = "260"
requestLengthDiskThreshold="80"/>
(根据需要增加数量)