繁体   English   中英

带有 IIsExpress 配置文件的 ASP.NET Core 6 文件太大 (413)

[英]ASP.NET Core 6 File too large (413) with IIsExpress Profile

我想将一个大小约为 80Mb 的文件上传到我的控制器:

[HttpPost("UploadJar")]
[RequestFormLimits(MultipartBodyLengthLimit = 104857600)]
public ActionResult UploadJar([FromForm]IFormFile file)
{
            if (file is not { Length: > 0 })
            {
                return BadRequest();
            }

            var filePath = $"{Path.GetTempPath()}{Guid.NewGuid()}.jar";

            using (var stream = System.IO.File.Create(filePath))
            {
                file.CopyTo(stream);
            }

            if (ValidateJarFile(filePath) == false)
            {
                System.IO.File.Delete(filePath);
                return BadRequest();
            }

            HttpContext.Session.SetString("jarFileTempPath", filePath);
            return Ok();
}

我的Startup类包含以下配置:

services.Configure<IISServerOptions>(options =>
    {
        options.MaxRequestBodySize = 120000000; // 120Mb
    });
    
services.Configure<KestrelServerOptions>(options =>
    {
        options.Limits.MaxRequestBodySize = 120000000; // 120Mb, if don't set default value is: 30 MB
    });

我与 Jetbrains Rider 一起使用的配置文件是:

  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "ASP.NETCoreWebApplication": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }

当我使用配置文件ASP.NETCoreWebApplication ,一切都很好,但如果我使用配置文件IIS Express ,上传文件时会出现 413(文件太大)错误。

谁能给我解释一下?

在网络中。 在 System.WebServer 下配置你需要把它。 或者,如果您使用的是 Rider,则在 Rider 应用程序主机文件中使用它。

<security>
<requestFiltering>
    <requestLimits maxAllowedContentLength="524288000"/>
</requestFiltering>
</security>

请参阅以下链接 - IIS Express 的默认限制 <limits>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM