如何使用 ASP.NET MVC 增加 AJAX JSON 响应的 2MB 限制
当响应超过 2MB 时,我在进行 AJAX 调用时遇到问题。任何响应小于 2MB 的东西都可以正常工作。当响应超过 2MB 时,我的“成功”方法永远不会被调用。
我的应用程序是 ASP.NET MVC2。我使用 jQuery AJAX 调用进行调用:
$.ajax({
type: "post",
data: ajaxData,
url: ajaxUrl,
success: updateItems,
cache: false
});
在我的控制器中,我使用 Json() 操作结果方法:
public ActionResult GetItems(....)
{
...
return Json(packet);
}
当我在 Fiddler 中观看调用时,它会返回 HTTP 500 响应。
我尝试在 Web.config 文件中设置 maxJsonLength,如下所示 此处,但这似乎没有任何区别。
关于如何允许超过 2MB 的响应有什么建议吗?
预先感谢,
跳过
I am having problems making an AJAX call when the response is over 2MB. Anything with a response under 2MB works fine. When the response is over 2MB, my "success" method never gets called.
My application is ASP.NET MVC2. I am making the call using the jQuery AJAX call:
$.ajax({
type: "post",
data: ajaxData,
url: ajaxUrl,
success: updateItems,
cache: false
});
In my controller, I am using the Json() action result method:
public ActionResult GetItems(....)
{
...
return Json(packet);
}
When I watch the call in Fiddler it comes back with a HTTP 500 response.
I tried setting the maxJsonLength in the Web.config file as shown here, but that doesn't seem to make any difference.
Any suggestions on how to allow a response over 2MB?
Thanks in advance,
Skip
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将以下内容添加到 web.config 中:
You could add following to the web.config:
我不确定您是否正在运行自己的服务器,或者您是否使用托管解决方案,但是,我们最近遇到了这个问题,但有 30MB 的限制。任何更大的东西都不会激发成功方法。因此,如果您使用共享主机,则此设置可能已设置为 2MB。
我们通过更改 maxAllowedContentLength 修复了此问题,如下所述:
http://www.webtrenches.com/post.cfm/iis7 -文件上传大小限制
I am not sure if you are running your own server or if you are on a hosted solution, however, we recently ran into this but with a 30MB limit. Anything greater would not fire success methods. So if you are on a shared host this setting might have been set to 2MB for you.
We fixed this by changing the maxAllowedContentLength as described here:
http://www.webtrenches.com/post.cfm/iis7-file-upload-size-limits
更改executionTimeout和maxRequestLength可能是解决方案,因为您说:“我的‘成功’方法永远不会被调用。” (它解决了我添加此问题的问题。)
来源:https://webconnection.west- Wind.com/docs/_4lp0zgm9d.htm
Changing executionTimeout and maxRequestLength might be the solution cause you stated: "my 'success' method never gets called." (It solved my problem with adding this.)
Source : https://webconnection.west-wind.com/docs/_4lp0zgm9d.htm