首页 > 解决方案 > 使用 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;
}

根据以前的答案,我尝试了以下方法:

我不确定我还能尝试什么。

Anyone ever fix this before?

Thanks!

标签: visual-studiovisual-studio-2019iis-express

解决方案


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.

See : https://support.pkware.com/home/smar/latest/sem-knowledge-base/kb-granting-folder-permissions-to-iis-application-pools

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.


推荐阅读