【问题标题】:Access to path wwwroot is denied even though I have permission即使我有权限访问路径 wwwroot 也被拒绝
【发布时间】:2018-10-14 12:45:31
【问题描述】:

我正在使用此代码将文件上传到(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:对路径“C:\inetpub\wwwroot\LogonChecker\wwwroot”的访问被拒绝。

new FileStream 线上..

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

我在 Windows 7 上使用 IIS 6.1。

【问题讨论】:

  • 无论权限如何,都不能像文件一样写入文件夹
  • 您是否为 IIS_IUSRS 设置了该文件夹的权限?

标签: c# iis permissions windows-7 asp.net-core-mvc


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 2014-08-10
    相关资源
    最近更新 更多