【发布时间】: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