5

I'm using this code to upload a file to the (Windows 7) server

[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});
}

It works great when debugging in VSCode, but after publishing I get

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

on the new FileStream line..

  • I granted full control permissions for that folder for the user running the app pool
  • I changed the application pool identity to Network Service and also granted full control permissions
  • I enabled Anonymous Authentication ISS and tried to set it to both "use Application Pool Identity" and "specific user" (for which I specified a user who has full control permissions on the folder)
  • I tried unchecking the "read only" box in the folder properties, but whenever I look again it is rechecked...
  • I refreshed the site and recycled the app pool after making each of the above changes

I'm using IIS 6.1 on Windows 7.

Bassie
  • 9,529
  • 8
  • 68
  • 159

1 Answers1

4

As far as I remember you need to set permissions on that folder for IIS_IUSRS so that your process can access it.

mr100
  • 4,340
  • 2
  • 26
  • 38