[英]Generic handler parameter size limit?
我有一些JavaScript代碼,該代碼會生成一個很長的腳本,然后將其發布回服務器到用於創建csv的通用處理程序中。
我用於發送數據的JavaScript代碼是:
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);
}
在我的控制台中,我可以看到整個字符串都添加到了表單中(“ console.log(k +':'+ p [k]);”;因此客戶端似乎可以正常工作。
在檢查請求/響應的網絡視圖中,我可以看到“內容”(表單數據屬性的名稱)不完整-在中間被剪切了。
服務器端非常簡單-將內容作為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;
}
}
}
我的猜測是服務器需要以某種方式配置以允許更大的帖子...
您可以在web.config中設置允許的最大內容長度。 默認值為30,000,000字節:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="[maxLengthInBytes]" />
</requestFiltering>
</security>
...
</system.webServer>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.