c# - 通用处理程序参数大小限制?

标签 c# javascript asp.net post ashx

我有一些 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]);"所以客户端似乎工作正常。

在我检查请求/响应的 WebView 中,我可以看到“内容”(表单数据属性的名称)不完整 - 它在中间被切断。

服务器端非常简单 - 以 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>

关于c# - 通用处理程序参数大小限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15920985/

相关文章:

c# - 有没有一种简单的方法可以在 LINQ to Entities 中编写自定义函数?

javascript - 将带有 null 或 undefined 的 javascript 函数绑定(bind)为 thisArg

javascript - 使用 EaselJS 位图时捕获错误的 URL

javascript - 在 IE Mobile 中捕获 javascript 事件

c# - 尝试从 azure blob 存储读取 parquet 数据时出现异常(使用 ChoETL)

c# - 如何获取DataGridView中的数据?

c# - 使用 lock(typeof(string)) 的含义是什么

c# - 使用 mschart 在数据点上设置标签

asp.net - 被迫使用过多的隐藏字段;寻找替代方法

c# - 关于 c# 接口(interface)和泛型的问题