2

I have some JavaScript code which generates a very long script and than posts it back to the server to a generic handler for creating a csv.

My JavaScript Code for sending the data is:

function postwith(to, p) {
var myForm = document.createElement("form");
myForm.method = "post";
myForm.action = to;
for (var k in p) {
    var myInput = document.createElement("input");
    myInput.setAttribute("name", k);
    myInput.setAttribute("value", p[k]);
    console.log(k+":"+p[k]);
    myForm.appendChild(myInput);
}
document.body.appendChild(myForm);
myForm.submit();
document.body.removeChild(myForm);

}

In my console I can see that the entire string is added to the form ("console.log(k+':'+p[k]);" so the client side seems to work ok.

In the network view where I examine the request/response I can see that "Content" (the name of the form data attribute) is not complete - it is cut in the middle.

The server side is very simple - sends back the content as csv:

public class Excel : IHttpHandler {

public void ProcessRequest (HttpContext context) {

    context.Response.ContentType = "text/csv";
    context.Response.AddHeader("Content-Disposition", "attachment; filename=" + context.Request["Report"] +System.DateTime.Now.Ticks+ ".csv");
    string content = context.Request["Content"];
    content = content.Replace(";", System.Environment.NewLine);
    System.Text.UTF8Encoding uc = new System.Text.UTF8Encoding(true);
    context.Response.Output.WriteLine(content);
    context.Response.End(); 
}

public bool IsReusable {
    get {
        return false;
    }
}

}

MY guess is the server needs to be configured somehow to allow larger posts...

Doron Goldberg
  • 643
  • 1
  • 9
  • 23

1 Answers1

0

You can set the maximum allowed content length in the web.config. The default value is 30,000,000 bytes:

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="[maxLengthInBytes]" />
    </requestFiltering>
  </security>
  ...
</system.webServer>
Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
  • adding maxAllowedContentLength="4294967295" made no difference – Doron Goldberg Apr 10 '13 at 09:05
  • What's the length of your request and what's the length of the trimmed content? – Dennis Traub Apr 10 '13 at 09:59
  • THe csv is 515KB so this is the size which reaches the server and its about 1/2 the size of the original request. (so its not that large...) – Doron Goldberg Apr 10 '13 at 10:08
  • Have you looked at the actual request being posted? Or tried posting it manually, with Fiddler for example? Just to make sure it's a server-side issue. – Dennis Traub Apr 10 '13 at 10:14
  • Thing is the server is not throwing any errors. I see in chrome that the client side has the entire string (using console.log) but in the network tab I see the request has a partial string sent to the server. I'll try fiddler as well and see if anything new appears. – Doron Goldberg Apr 10 '13 at 10:18
  • I tried using IE instead of chrome - and now it works fine! anything I can do to fix it? – Doron Goldberg Apr 10 '13 at 10:26
  • @DoronGoldberg , I'm seeing the same problem in Chrome, works fine in explorer. Did you manage to solve this issue? Thanks , Omer – omer schleifer Aug 08 '13 at 07:40