大尺寸 (1MB) post 使用 FireFox + IIS + https + Windows 身份验证时 HTTP 错误 400

HTTP Error 400 when large size (1MB) post with FireFox + IIS + https + Windows Authentication

问题

我收到“HTTP 错误 400。请求动词无效。”当我在使用 ASP.NET 核心创建的应用程序中执行大尺寸 (1MB) post 时出错。

此问题仅在 Firefox 中出现,并且仅在启用 https 并使用 Windows 身份验证时出现。

我想知道如何解决这个大小限制。

发生条件

我检查了什么

验证码

Form.cs

public class Form
{
    public string Value { get; set; }
}

Controller.cs

public class HomeController : Controller
{
    [Authorize]
    [HttpGet]
    public IActionResult Index(int? size)
    {
        return View(new Form { Value = new string('X', size ?? 1024 * 1024) });
    }

    [Authorize]
    [HttpPost]
    public IActionResult Index(Form form)
    {
        return View(form);
    }
}

Index.cshtml

@model WebApplication.Models.Form
@{
    ViewData["Title"] = "Home Page";
}

<div>@Model.Value.Length</div>

<form method="post" asp-antiforgery="false">
    <input type="hidden" asp-for="Value"/>
    <button type="submit">Post</button>
</form>

Startup.cs

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication(IISDefaults.AuthenticationScheme);
        services.AddControllersWithViews();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseDeveloperExceptionPage();
        app.UseStaticFiles();
        app.UseRouting();
        app.UseAuthorization();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}

浏览器差异

协议和身份验证文件

尺寸界限

“值=”长度 6 + 1048570 = 1MB。

不明点

根据您的描述,我进行了测试,确实存在这个问题。

我在IIS日志中发现这个错误其实不是400错误而是401错误。也说明浏览器和服务器之间的验证有问题

您也可以在 IIS 中使用 FRT 来捕获此错误:

下面是使用 FRT 捕获的错误日志:

我们可以看到IIS中出现了401.2的错误。本质上,401.2 通常不是“错误”。这是身份验证的挑战。您的浏览器无法正确响应挑战。