如何增加JSON大小限制ASP.NET的WebAPI邮政电话? [英] How to increase the json size limit for ASP.NET WebAPI Post call?

查看:416
本文介绍了如何增加JSON大小限制ASP.NET的WebAPI邮政电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上的形式是有点过大。它收集月度测量数据。请看一看该示例:

My form on the page is a little too large. It collects the monthly measurement data. Please take a look at the sample:

{
"Year":2013,
"Month":3,
"Records":[
    {"Id":0,"Date":"3/1/2013","RiverSection":5,"UserNumber":56},
    {"Id":0,"Date":"3/1/2013","RiverSection":7,"UserNumber":200},
    {"Id":0,"Date":"3/1/2013","RiverSection":8,"UserNumber":556},
    {"Id":0,"Date":"3/2/2013","RiverSection":5,"UserNumber":56},
    {"Id":0,"Date":"3/2/2013","RiverSection":7,"UserNumber":200},
    ...
    ...
    {"Id":0,"Date":"3/31/2013","RiverSection":7,"UserNumber":200}
}

所以我张贴的大数据到APIController。

So I am posting the big data to an APIController.

我使用Visual Studio调试器的服务器工作在我的本地机器的罚款。但是,我上传了code到服务器之后(IIS 6)。它给出了一个 500内部服务器错误

I works fine in my local machine using the Visual Studio debugger server. But after I uploaded the code to the server (IIS 6). It gives a 500 Internal Server Error.

我想张贴一些示例数据,并检查了字符串化的JSON的长度。

I tried posting some sample data and checked the length of the stringified json.

在一个样本数据集,我的JSON的长度为5743,而我得到了一个成功。但是,如果JSON规模上升到17345,我得到了一个 500内部服务器错误

In one sample data set, the length of my json is 5743, and I got a "success". But if the json size goes up to 17345, I got a 500 Internal Server Error.

于是,我就增加JSON的极限。底座上的this帖子

So I tried to increase the limit of json. Base on this post

的Web.Config

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

但它不工作。

有另一种答案,使用:

var serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;

但是,我们应该在哪里把这个code?在的Global.asax

请注意我使用的是IIS 6,所以它是一个问题吗?我怎样才能正确地增加JSON大小的限制,所以,我的数据能打到的WebAPI行动?

Please note I am using an IIS 6. So is it a problem? How can I correctly increase the limit of json size so that my data can hit the WebApi action?

感谢您的任何援助。
  

Thank you for any assistance.

推荐答案

尝试添加 ASPNET:在的appSettings >在的web.config

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

来源:
有大量的表格项,文件,或JSON有效载荷的成员的ASP.NET请求失败,异常

这篇关于如何增加JSON大小限制ASP.NET的WebAPI邮政电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆