问题
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...
回答1:
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>
来源:https://stackoverflow.com/questions/15920985/generic-handler-parameter-size-limit