【问题标题】:Increase length of the query string for the $.get增加 $.get 的查询字符串的长度
【发布时间】:2018-12-20 14:32:59
【问题描述】:

我正在研究 MVC-5,我有使用 jquery get 函数下载 Excel、PDF、DOC 文件的场景。下面是代码sn-p:-

    var url = '@Html.Raw(@Url.Action("RendertoEXCEL", "Reports", new { ObjSSRSExportTemplates = @Html.Raw(Json.Encode(@ViewBag.ExportObj)) })) ';

    $.get(url, function (res)
    {

        window.location = url;
        $("#ResultConsReport").mLoading('hide');
    });

动作级别代码如下:-

 public ActionResult RendertoEXCEL(string ObjSSRSExportTemplates)
        {
            byte[] ReadRequest = null;
            JavaScriptSerializer js = new JavaScriptSerializer();
            ExportReportConfig objExport = js.Deserialize<ExportReportConfig>(ObjSSRSExportTemplates);
            string RptFomrat = "EXCEL";
            SSRSReportManager rptManager = new SSRSReportManager(RServiceURL, RptUserName, RptPassword);
            ReadRequest = rptManager.ExportReport(RDirName, objExport.ReportName, RptFomrat, objExport.parmaters);

            return File(ReadRequest, "application/vnd.ms-excel", "Report.xls");
        }

它工作得很好,但是当参数长度大小扩展时。它抛出错误:

此请求的查询字符串长度超过了配置的 maxQueryStringLength 值。

我google了一下,增加了:

maxUrlLength="10999" maxQueryStringLength="2097151"

在网络配置中但无法正常工作。有没有增加查询字符串的最大长度大小的解决方案?

【问题讨论】:

  • 您可能想尝试在 Web.config 的 system.webServer 部分添加 &lt;requestLimits maxUrl="10999" maxQueryString="2097151" /&gt;(如图所示 here
  • 请注意,每个浏览器也会有一个最大查询长度,超过该长度后它将被截断。

标签: jquery asp.net-mvc-5 getjson


【解决方案1】:

您正在尝试以不打算起作用的方式使用查询字符串,它并不意味着在客户端和服务器之间传递大量数据。您想传递多少数据?

在我看来,解决您的问题的最佳方法是在服务器端而不是客户端生成ExportObj,无论它是什么。

如果这不可行,请将您的 $.get 更改为 $.post 并在帖子正文中而不是在查询字符串中传递对象。像这样:

var url = '@Url.Action("RendertoEXCEL", "Reports")';
var data = { 
    ObjSSRSExportTemplates = @Html.Raw(Json.Encode(ViewBag.ExportObj))
};

$.post(url, data, function (res) {
    // logic
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 2021-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多