【问题标题】:Using virtual directory with ASP.NET Core 3.1在 ASP.NET Core 3.1 中使用虚拟目录
【发布时间】:2020-10-20 19:42:11
【问题描述】:

在 ASP.NET 框架 4.8 及以下版本中,Web 应用程序使用 IIS 来处理和显示数据。当我们需要使用文件夹和网络资源等其他资源时,我们可以轻松地在 IIS 中创建虚拟目录并映射到物理路径和我的应用程序工作主题,如普通文件夹。 但在 Net Core 中,我们使用 Kestrel 和 IIS 作为代理和 Kestrel 无法识别的虚拟目录。我使用此代码但无法正常工作。将此部分写在配置函数中

app.UseFileServer(new FileServerOptions
{
 FileProvider = new PhysicalFileProvider(@"E:\\MyFiles"),
 RequestPath = new PathString("/PFiles"),
 EnableDirectoryBrowsing = true
});

这是我的代码:

var folder = Path.Combine(environment.WebRootPath, "temp");


                var fileName = Path.Combine(environment.WebRootPath, "temp\\test.jpeg");

                var basePath = Path.Combine(environment.WebRootPath, "PFiles");
               
                
                var yearPath = Path.Combine(basePath, "2020");
                var monthpath = Path.Combine(basePath, "2020", "06");

                if (!Directory.Exists(yearPath))
                {
                    Directory.CreateDirectory(yearPath);
                }
                if (!Directory.Exists(monthpath))
                {
                    Directory.CreateDirectory(monthpath);
                }

                var dpath = Path.Combine(basePath, "2020", "06");

                var destinationPath = Path.Combine(environment.WebRootPath, dpath);


                System.IO.File.Move(fileName, destinationPath);

但我收到 拒绝访问错误 或在 wwwroot 文件夹内创建目录。那么,我该怎么办?

【问题讨论】:

  • 显示实际的错误页面。

标签: asp.net-core iis kestrel


【解决方案1】:

您收到此错误是因为 iis 默认帐户没有足够的权限访问该文件夹。

您可以尝试将 iis_iusrs 、 iusr 或 IIS AppPool 权限分配给您要创建目录的文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多