visual-studio - 使用 IIS Express 和 Visual Studio 调试项目时出现持久访问被拒绝消息
问题描述
我正在 Visual Studio 2019 中调试我的 NetCore 3.1 项目。我正在使用 Windows 10 上的内置 IIS Express 在本地执行此操作。
我正在尝试将文件保存到我的 D: 驱动器。
使用 IIS Express 在调试模式下运行 Visual Studio 项目时,当我尝试将文件复制到本地文件系统时,出现以下错误:
{"Access to the path 'D:\\biologyMedia\\eb4cf4c2-6434-4cfe-9fa8-0033bc9b1a08' is denied."}
错误发生在 try 块中的以下方法中:
public async Task<bool> CopyFile(IFormFile examFile, Guid diseaseId)
{
string path = @"D:\biologyMedia\" + diseaseId + @"\";
if (!Directory.Exists(path))
{
DirectoryInfo di = Directory.CreateDirectory(path);
}
try
{
using (var fileStream = new FileStream(path, FileMode.Create))
{
await examFile.CopyToAsync(fileStream);
}
} catch (Exception e)
{
var error = e.InnerException;
return false;
}
return true;
}
根据以前的答案,我尝试了以下方法:
- 在项目属性中将 Windows 身份验证设置为启用
- 以管理员身份启动 Visual Studio
- 完全控制 D: 驱动器到 LOCAL SERVICE、NETWORK SERVICE、IUSR、IIS_USERS 和 NETWORK,以及我自己的 Windows 帐户(它是管理员的成员)。
我不确定我还能尝试什么。
Anyone ever fix this before?
Thanks!
解决方案
I have had similar adventures in the past, with IIS, but I have never worked with IIS Express. In my case I had to grant the application pool user access to the folder.
I suggest you check your applicationhost.config to examine your application pools in IIS Express. And ensure that the application pool of IIS Express has complete control of the folder D:\biologyMedia
.
Hope this helps.
推荐阅读
- c - 无法使用共享 C 库中的函数 cpuset_create
- google-bigquery - 在 bigquery 中拆分字符串
- python - 如果满足条件,则迭代数据帧的行并检索列的值
- wordpress - 如何访问 azure 上的 Wordpress 文件和我的 wp-admin 显示 403 禁止错误
- android - 有什么方法可以拦截 android 上 WebView 上的 websocket 连接?
- javascript - 在选项卡更改时触发窗口重新加载以更新 React 中的选项卡内容
- elasticsearch - 弹性嵌套布尔查询的输出之间的差异
- r - 在 geom_point 中填充区域
- pentaho - Pentaho91:将数据网格行复制到两个合并连接。这是一个错误吗?
- css - 居中可折叠但内容下降