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

Bas*_*sie 5 c# iis permissions windows-7 asp.net-core-mvc

我正在使用此代码将文件上传到(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});
}
Run Code Online (Sandbox Code Playgroud)

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

UnauthorizedAccessException: 拒绝访问路径“C:\inetpub\wwwroot\LogonChecker\wwwroot”。

new FileStream线了。。

  • 我为运行应用程序池的用户授予了对该文件夹的完全控制权限
  • 我将应用程序池标识更改为网络服务并授予完全控制权限
  • 我启用了匿名身份验证 ISS 并尝试将其设置为“使用应用程序池身份”和“特定用户”(为此我指定了一个对文件夹具有完全控制权限的用户)
  • 我尝试取消选中文件夹属性中的“只读”框,但是每当我再次查看时,它都会重新选中...
  • 在进行上述每项更改后,我刷新了站点并回收了应用程序池

我在 Windows 7 上使用 IIS 6.1。

mr1*_*100 4

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