.NET MVC 4 JSON Post/Put char limit in Web.config

可紊 提交于 2019-12-02 11:02:56

问题


I am using the PUT verb to send JSON to a MVC controller. When I reach a certain limit I get a 500 error. If I scale back the JSON I send, then it sends just fine... Does anyone know of a configuration in the web.config that will allow a larger amount of JSON to be passed to my application?


回答1:


Here is the answer... My JSON object was quite large so .NET wouldn't allow it to pass due to a "security feature" The default is 2000, so I bumped it and it worked perfectly.

  <add key="aspnet:MaxJsonDeserializerMembers" value="5000"/>



回答2:


Approach - 1

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

Approach - 2

<location path="File Path or FileHandler.ashx">
  <system.web>
    <httpRuntime executionTimeout="your value" maxRequestLength="Your value" />
  </system.web>
</location>

Using this approach, we can set the limits for specific page and not for the complete application.

Approach - 3

<httpRuntime targetFramework="Your version" maxRequestLength="Your value" />

Using this approach, we can set the limits for complete application.




回答3:


Check the maxRequestLength in your web.config. If the data exceeds maxRequestLength, 500 status is returned.

<httpRuntime targetFramework="4.5" maxRequestLength="XXX" />

Note: if maxRequestLength isn't specified. Default value is 4MB.

If that doesn't work, try IIS's Request Limits. Documentation however says that 404 status should be returned.



来源:https://stackoverflow.com/questions/15788342/net-mvc-4-json-post-put-char-limit-in-web-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!