访问路径 wwwroot 被拒绝,即使我有权限

Access to path wwwroot is denied even though I have permission

我正在使用此代码将文件上传到 (Windows 7) 服务器

[HttpPost]
public IActionResult Upload(string office, IFormFile file)
{
    var webRootPath  = _environment.WebRootPath;
    var floorPlanPath =  _configuration["SydneyFloorplanPath"];

    if (file.Length > 0) {
        var filePath1 = Path.Combine(floorPlanPath,webRootPath.ReplaceFirst("/", ""));

        using (var fileStream = new FileStream(filePath1, FileMode.Create)) {
            file.CopyTo(fileStream);
        }
    }
    return RedirectToAction("Index", new{office = office});
}

在 VSCode 中调试时效果很好,但发布后我得到

UnauthorizedAccessException: Access to the path 'C:\inetpub\wwwroot\LogonChecker\wwwroot' is denied.

new FileStream 行..

我在 Windows 7.

上使用 IIS 6.1

据我所知,您需要为 IIS_IUSRS 设置该文件夹的权限,以便您的进程可以访问它。