将大型JSON发布到MVC操作方法:字符串的长度超过该值

时间:2017-03-19 20:17:39

标签: json asp.net-mvc

我正试图在mvc动作方法中发布大json。 导致错误

  

使用JSON进行序列化或反序列化时出错   JavaScriptSerializer。字符串的长度超过了设置的值   在maxJsonLength属性上。参数名称:输入

我知道在SO和google上有很多帖子,我尝试了很多解决方案,但没有一个能为我工作:

我尝试过的: 更新了 Web.Config

system.web

中更新了此声明
<httpRuntime targetFramework="4.5.1" maxRequestLength="1073741824"  />

以及Systerm.webserver中的以下行

<security>
      <requestFiltering>
                <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>

添加上面的行后,它在本地工作,但在服务器上更新相同的值后它不起作用,它会抛出错误。

更新

IIS Version 7.5

2 个答案:

答案 0 :(得分:1)

您是否尝试过以下方法:

  1. 将数据作为对象发送,而不像下面的ajax调用中的url参数那样。

          $.ajax({
                    type: "POST",
                    url: url,
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(data),
                    dataType: "json",
                    success: function (data) {
    
                    },
                    error: function (a, b, c) { console.log(a); }
                });
    
  2. 您可以看到我的POST

答案 1 :(得分:0)

尝试将以下内容添加到您的web.config

<configuration>
  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="{required length of json in bytes}" />
      </webServices>
    </scripting>
  </system.web.extensions>
</configuration>

最大值为2147483647,默认值为102400(100kb),这可能是您的问题。