我可以在 web.config 中为 maxJsonLength 设置无限长度吗? [英] Can I set an unlimited length for maxJsonLength in web.config?
问题描述
我正在使用 jQuery 的自动完成功能.当我尝试检索超过 17000 条记录的列表(每条记录的长度不超过 10 个字符)时,它超出了长度并引发错误:
<块引用>异常信息:
异常类型:InvalidOperationException
异常消息:使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错.字符串的长度超过了 maxJsonLength 属性上设置的值.
我可以在 web.config
中为 maxJsonLength
设置无限长度吗?如果不是,我可以设置的最大长度是多少?
注意:此答案仅适用于 Web 服务,如果您从 Controller 方法返回 JSON,请务必阅读此 SO回答如下:https://stackoverflow.com/a/7207539/1246870
<小时>MaxJsonLength属性不能是无限制的,是一个整数属性,默认为 102400 (100k).
您可以在 web.config 上设置 MaxJsonLength
属性:
I am using the autocomplete feature of jQuery. When I try to retrieve the list of more then 17000 records (each won't have more than 10 char length), it's exceeding the length and throws the error:
Exception information:
Exception type: InvalidOperationException
Exception message: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Can I set an unlimited length for maxJsonLength
in web.config
? If not, what is the maximum length I can set?
NOTE: this answer applies only to Web services, if you are returning JSON from a Controller method, make sure you read this SO answer below as well: https://stackoverflow.com/a/7207539/1246870
The MaxJsonLength property cannot be unlimited, is an integer property that defaults to 102400 (100k).
You can set the MaxJsonLength
property on your web.config:
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
这篇关于我可以在 web.config 中为 maxJsonLength 设置无限长度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!