【问题标题】:how big can be the string sent back to the server with the following code?使用以下代码发送回服务器的字符串可以有多大?
【发布时间】:2012-05-21 07:21:34
【问题描述】:

您好,我需要将一些数据发送回服务器,我想使用以下代码。

有人知道用下面的代码发送的字符串的维度是否有限制

这是我的 js 代码:

 $(document).ready(function() {

          $.ajax({
              type: "POST",
              url: "test.aspx/PassBackdata",
              contentType: "application/json; charset=utf-8",
              data: "{'args': '" + Ldata + "'}",
                   dataType: "json",
                   success: AjaxSucceeded,
                   error: AjaxFailed
               });
           });


      };

【问题讨论】:

    标签: jquery asp.net postback


    【解决方案1】:

    由于您使用的是 POST,因此您发送到服务器的数据可能非常大,并且由 web.config 中的 <httRuntime> 元素控制:

    <!-- Limit the request size to 4MB -->    
    <httpRuntime maxRequestLength="4096" />
    

    如果您在 IIS7+ 中托管,您还应该使用 &lt;requestLimits&gt; 标签:

    <system.webServer>
        <security>
            <requestFiltering>
                <!-- Limit the request size to 4MB -->    
                <requestLimits maxAllowedContentLength="4194304" />
            </requestFiltering>
        </security>
    </system.webServer>
    

    另外我建议你使用JSON.stringify 方法来确保数据被正确编码:

    $.ajax({
        type: "POST",
        url: "test.aspx/PassBackdata",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify({ args: Ldata }),
        dataType: "json",
        success: AjaxSucceeded,
        error: AjaxFailed
    });
    

    【讨论】:

    • 或者通过任何面向公众的 Web 服务器的相应配置来代理您对 ASP 的请求。
    【解决方案2】:

    这取决于服务器设置 - 它将接受多少数据以及等待数据多长时间。通常默认设置为几 MB(PHP 为 8 MB,对于 ASP.NET 不确定),但这取决于配置。但是,大数据会影响用户体验,并且页面在达到网络服务器限制之前可能会明显变慢。

    【讨论】:

      【解决方案3】:

      Web 服务器通常对请求的大小有限制。它因一种服务器类型而异,并且是可配置的。

      例如,Windows IIS 的默认限制是 4 MB。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-10-13
        • 1970-01-01
        • 1970-01-01
        • 2012-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多