我在页面上的表单有点太大了.它收集月度测量数据.请看一下样本:
{
"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}
}
Run Code Online (Sandbox Code Playgroud)
所以我将大数据发布到APIController.
我在使用Visual Studio调试器服务器的本地计算机上工作正常.但是我将代码上传到服务器(IIS 6)之后.它给了一个500 Internal Server Error.
我尝试发布一些示例数据并检查字符串化json的长度.
在一个样本数据集中,我的json的长度是5743,我得到了"成功".但如果json大小达到17345,我得到了一个500 Internal Server Error.
所以我试图增加json的限制.基于这篇文章
在Web.Config:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="5000000">
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
Run Code Online (Sandbox Code Playgroud)
但它没有用.
还有另一个答案,使用:
var serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
Run Code Online (Sandbox Code Playgroud)
但是我们应该在哪里放置这些代码?在Global.asax?
请注意我使用的是IIS 6.所以这是一个问题吗?如何正确增加json大小的限制,以便我的数据可以达到WebApi操作?
谢谢你的帮助.
所以我们已经从3.5 SP1升级了我们的站点 - > .NET 4.
当我们运行该站点时,我们收到内部服务器错误(500),说明无法读取以下配置组:
<system.web.extensions>
<scripting>
<scriptResourceHandler enableCompression="true" enableCaching="true" />
<webServices>
<jsonSerialization maxJsonLength="999999" />
</webServices>
</scripting>
</system.web.extensions>
Run Code Online (Sandbox Code Playgroud)
我们注释掉了这一部分并且网站运行正常(但现在我们遇到了JSON的问题 - 因为上面要求的属性).
我们已经阅读了关于这个问题的线程,并且大多数人都说"你的应用程序池没有运行4.0".它就是,所以这不是问题.
我还读过线程,说IIS正在以某种方式读取旧的machine.config文件.
使用.NET 4,您知道web.config的许多部分已移至machine.config.
所以我们把这部分放回web.config的顶部:
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="authenticationService" …Run Code Online (Sandbox Code Playgroud) asp.net ×1
asp.net-4.0 ×1
deployment ×1
jquery ×1
json ×1
json.net ×1
system.web ×1
web-config ×1