0

I am working on MVC-5, I have scenario where I am downloading Excel,PDF,DOC files using jquery get function. Below is code snippet:-

    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');
    });

Action Level Code IS as below:-

 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");
        }

It working very fine, but when in case parameter length size extends. It throws error :

The length of the query string for this request exceeds the configured maxQueryStringLength value.

I googled and increase:

maxUrlLength="10999" maxQueryStringLength="2097151"

in web config but not working. Is there any solution for increase maximum length size of querystring?

Vsagar
  • 197
  • 2
  • 17
  • You may want to try adding `` in `system.webServer` section of your Web.config (as shown [here](https://stackoverflow.com/a/9743176/4636715) ) – vahdet Jul 12 '18 at 11:24
  • Be aware that each browser will also have a maximum query length after which it will get truncated. – phuzi Jul 12 '18 at 11:27

1 Answers1

1

You're trying to use the query-string in a way it's not intended to function, it's not meant to pass vast amounts of data between client and server. Just how much data are you trying to pass?

The best solution to your problem in my eyes is to generate the ExportObj, whatever it may be, on the server side instead of on the client.

If that's not possible, change your $.get to a $.post and pass the object in the post body instead of in the query string. Like so:

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

$.post(url, data, function (res) {
    // logic
});
Andreas Eriksson
  • 8,979
  • 8
  • 47
  • 65