Recently, I ran into a problem with my application: the size of the JSON string returned from the server was exceeding the default maxJsonLength. I've done some research and implemented some fixes including a variation of paging. Everything looks great at the moment. However, I still have some questions unanswered.
最近,我的应用程序遇到了一个问题:从服务器返回的JSON字符串的大小超过了默认的maxJsonLength。我做了一些研究并实现了一些修复,包括分页的变化。现在一切看起来都很好。然而,我仍然有一些问题没有得到解答。
First of all, the majority of the sources point to this article: http://geekswithblogs.net/frankw/archive/2008/08/05/how-to-configure-maxjsonlength-in-asp.net-ajax-applications.aspx
1. Why 2,097,152 (2MB)? 2MB is way too much data to be loaded for a web page. (Unless, the user is downloading something, but that's a different story) Even 1MB is too much.
2. Than, the author goes on with an example of maxJsonLength of 500,000. Why this number? Is this just an example of how to set the property? Some sources state that 500,000 is the limit. Well, it's not, because I tested my application with 2,097,152 (2MB, roughly 4 times the 500,000) and it worked.
3. Some other sources state that 4MB is the limit... So, what is the limit? Is there a limit? Does it have something to do with the limit of the response from the server?
4. Finally, I'd like to get a strong suggestion on a length of JSON string being received from the server. Not the number to which maxJsonLength should be set, but the actual length of the JSON string, kind of "what to strive for".
Thank you in advance.
首先,大多数源代码都指向这篇文章:http://geekswithblogs.net/frankw/archive/2008/08/05/how- configure-maxjsonlength-in-asp.net-ajax-applications.aspx 1。为什么2097152(2 mb)?2MB是太多的数据,无法载入网页。(除非用户正在下载某些东西,但那是另一回事)即使1MB也太多了。2。作者接着举了一个maxJsonLength为500,000的例子。为什么这个号码吗?这只是如何设置属性的一个例子吗?一些消息称,50万是上限。不是这样的,因为我测试了我的应用程序2097152 (2MB,大约是50万的4倍),它起作用了。3所示。其他一些资料指出4MB是极限……那么,极限是多少?有限制吗?它是否与服务器响应的限制有关?4所示。最后,我想对从服务器接收的JSON字符串长度提出强烈建议。不是应该设置maxJsonLength的数字,而是JSON字符串的实际长度,有点像“要争取什么”。提前谢谢你。
2 个解决方案
#1
1
There is no hard and fast rule here. Your Json length is going to depend on your application and what information you are returning to the client.
这里没有硬性规定。Json长度将取决于应用程序以及返回给客户端的信息。
If you really want a "rule of thumb", it should be as SMALL as possible to communicate the data that you need.
如果您真的想要一个“经验法则”,那么应该尽可能地少地交流您需要的数据。
For max values, the true limitation is again going to depend most likely on browser requirements, but I personally would never go with more than 2mb for a Json message simply due to what it would take to send that down.
对于max值来说,真正的限制可能再次取决于浏览器的需求,但是我个人不会仅仅因为要发送Json消息而使用超过2mb的内存。
#2
1
I understand that the total limit is determined by the lesser of the maxJsonLength that you have mentioned and the HttpRuntimeSection.MaxRequestLength. I am currently testing this and I will get back to you.
我理解,总极限是由您提到的maxJsonLength和httprunection . maxrequestlength的较小部分决定的。我现在正在测试这个,我会给你回复。
Of course, the big issue here is that it is seldom a good idea to return such large amounts of data. Whenever I have a response that starts to exceed about 100KB, I take another look at my overall design and find ways to serve out smaller chunks as they are needed. Even this 100KB is high for must pure data scenarios, by which I mean textual data, not images or scripts.
当然,这里的大问题是,返回如此大量的数据很少是一个好主意。每当我的响应开始超过100KB时,我就会再看一遍我的总体设计,并根据需要找到解决小块问题的方法。即使这个100KB对于纯数据场景来说也是很高的,我指的是文本数据,而不是图像或脚本。
#1
1
There is no hard and fast rule here. Your Json length is going to depend on your application and what information you are returning to the client.
这里没有硬性规定。Json长度将取决于应用程序以及返回给客户端的信息。
If you really want a "rule of thumb", it should be as SMALL as possible to communicate the data that you need.
如果您真的想要一个“经验法则”,那么应该尽可能地少地交流您需要的数据。
For max values, the true limitation is again going to depend most likely on browser requirements, but I personally would never go with more than 2mb for a Json message simply due to what it would take to send that down.
对于max值来说,真正的限制可能再次取决于浏览器的需求,但是我个人不会仅仅因为要发送Json消息而使用超过2mb的内存。
#2
1
I understand that the total limit is determined by the lesser of the maxJsonLength that you have mentioned and the HttpRuntimeSection.MaxRequestLength. I am currently testing this and I will get back to you.
我理解,总极限是由您提到的maxJsonLength和httprunection . maxrequestlength的较小部分决定的。我现在正在测试这个,我会给你回复。
Of course, the big issue here is that it is seldom a good idea to return such large amounts of data. Whenever I have a response that starts to exceed about 100KB, I take another look at my overall design and find ways to serve out smaller chunks as they are needed. Even this 100KB is high for must pure data scenarios, by which I mean textual data, not images or scripts.
当然,这里的大问题是,返回如此大量的数据很少是一个好主意。每当我的响应开始超过100KB时,我就会再看一遍我的总体设计,并根据需要找到解决小块问题的方法。即使这个100KB对于纯数据场景来说也是很高的,我指的是文本数据,而不是图像或脚本。