【问题标题】:500 Internal Server error when passing large data传递大数据时出现 500 内部服务器错误
【发布时间】:2018-09-20 06:40:41
【问题描述】:

我正在使用 ASP.NET MVC5 并通过 ajax 将对象列表传递给操作。 理想情况下,我想在列表中传递大约 10K 项,但由于某种原因,我不能传递超过 65 项。每次我尝试超过 65 时,我都会收到 500 内部服务器错误。我尝试使用断点进行调试,但似乎该调用甚至从未触发我的操作。动作代码是:

 public ActionResult DownloadExcel(List<DbEntity> list)
    {
        FileDataViewModel fileData = new FileDataViewModel { FileName = "foo", FilePath = "bar" };
        //I want to do something else here but that's not the point of this
        return Json(new { fileData });
    }

我的 Ajax 调用是:

            $('#btn').click(function () {
            dto = @Html.Raw(Json.Encode(Model));

            console.log(dto);
            //I have checked the console and the array is correct, there is  no problem with the dto variable 
            $.ajax({
                url: "/DbEntities/DownloadExcel",
                contentType: "application/json; charset=utf-8",
                method: "POST",
                data: JSON.stringify(dto),
            })
                .done(function (response) {
                    document.getElementById("mySpan").innerHTML = "<hr>File created successfully<br>";
                })
                .fail(function (response) {
                    document.getElementById("error").innerHTML = "Error creating file";
                });
        });

【问题讨论】:

  • &lt;system.web&gt;&lt;httpRuntime executionTimeout="240" maxRequestLength="51200" /&gt;&lt;/system.web&gt; 你能把它设置成web.config 再试一次吗?
  • @AdrianBrand @Win 我已经设置了这些但仍然没有运气&lt;requestLimits maxAllowedContentLength="1073741824" /&gt; &lt;httpRuntime targetFramework="4.5.2" maxRequestLength="1048576" executionTimeout="3600" /&gt;

标签: asp.net-mvc asp.net-web-api


【解决方案1】:

试试 maxJsonLength

<system.web.extensions>
    <scripting>
        <webServices>
            <!-- Try increasing this value to a larger value (Int.MaxValue used below) -->
            <jsonSerialization maxJsonLength="2147483644"></jsonSerialization>
        </webServices>
    </scripting>
</system.web.extensions>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 2016-08-21
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    相关资源
    最近更新 更多