Reputation: 10390
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'm using IIS 6.1 on Windows 7.
Upvotes: 5
Views: 4099
Reputation: 4428
As far as I remember you need to set permissions on that folder for IIS_IUSRS so that your process can access it.
Upvotes: 4