【问题标题】:Web Api max parameter lengthWeb API 最大参数长度
【发布时间】:2015-04-08 15:57:45
【问题描述】:

我有一个非常简单的 dto

public class RisRequest
{
    public string APIKey { get; set; }
    public string Message { get; set; }
}

还有一个不错的简单 web api

[HttpPost]
    public HttpResponseMessage rad(RisRequest request)

99% 的时间它都有效。但是当我遇到消息长于标准(>100,000 个字符和 112kb)的请求时,此参数为空。请注意 APIKey 仍然很好,我的 RisRequest 对象不是 null,而是只有 eMessage 参数。

我做了一些谷歌搜索并尝试了很多选项

根据This link,我尝试设置 httpconfig 缓冲区

config.Formatters.FormUrlEncodedFormatter.ReadBufferSize = int.MaxValue/10;

我尝试了this link 中的 web.config 选项

<system.webServer>
  <security>
   <requestFiltering>
    <requestLimits maxAllowedContentLength="2147483648" />
   </requestFiltering>
  </security>
</system.webServer>

<system.web>
  <httpRuntime maxRequestLength="2097152" />
</system.web>

也没有运气。所有其他一些建议相同的变体。 有什么想法我哪里出错了吗?

谢谢

【问题讨论】:

    标签: c#-4.0 asp.net-mvc-5 asp.net-web-api2


    【解决方案1】:

    根据Max Parameter length in MVC

    这是一个窗口限制。在您的网址中,参数是路径的一部分。 windows 限制路径段长度。

    您应该在 regedit 中更改 UrlSegmentMaxLength

    在以下注册表键中创建一个DWORD

    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters

    UrlSegmentMaxCount

    URL 路径段的最大数量。如果为零,则计数由 ULONG 的最大值。

    有效值范围 0 - 16,383

    【讨论】:

      猜你喜欢
      • 2014-05-20
      • 1970-01-01
      • 2012-12-03
      • 2021-04-22
      • 2015-06-12
      • 1970-01-01
      • 2013-09-15
      • 2015-12-30
      • 2023-03-24
      相关资源
      最近更新 更多