【问题标题】:How to solve "Request Header Too Long" on an Azure Web App如何解决 Azure Web App 上的“请求标头过长”
【发布时间】:2019-07-11 11:23:54
【问题描述】:

登录到我们管理门户的用户通过 Active Directory 获得权限。他们越来越多地遇到 400 错误 Bad Request (Request Header too long) 错误。

这是由 Microsoft 记录的: https://support.microsoft.com/en-us/help/2020943/http-400-bad-request-request-header-too-long-response-to-http-request

他们提出的解决方案是添加两个注册表项 - MaxFieldLength 和 MaxRequestBytes - 控制 URL 中允许的数据量。

但是,我们的网站在 Azure 中设置为 Web 应用程序。根据各种来源,包括这个 SO 问题 - How to Create an HKLM entry in Azure Website - 您无法更改 Web 应用程序上的注册表。

有没有办法解决这个问题?有趣的是,MS 建议的另一个解决方案是“减少用户所属的 Active Directory 组的数量”。但是我们已经把它降到了两个,但问题仍然存在。 URL 的最大组成部分是 QueryString 中的“状态”参数。

【问题讨论】:

    标签: c# azure iis asp.net-core-2.0 query-string


    【解决方案1】:

    假设您使用的是根据您的标签给出的 asp.net-core-2.0。您可以使用.UseKestrel(x => x ...)WebHost 上进行配置。

    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }
    
        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                // This is the line you want to add!
                .UseKestrel(x =>
                {
                    x.Limits.MaxRequestHeadersTotalSize = <your value?>;
                })
                .UseStartup<Startup>();
    }
    

    还有更多可用选项,例如MaxRequestHeaderCountMaxRequestLineSize

    【讨论】:

      猜你喜欢
      • 2021-01-17
      • 2016-08-02
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 2019-05-27
      • 2018-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多