Asp.net core 使用ASP.NET Core 3.1的虚拟目录

Asp.net core 使用ASP.NET Core 3.1的虚拟目录,asp.net-core,iis,kestrel,Asp.net Core,Iis,Kestrel,在ASP.NET framework 4.8及以下版本中,web应用程序使用IIS处理和显示数据。当我们需要使用其他资源(如文件夹和网络资源)时,我们可以轻松地在IIS中创建虚拟目录,并映射到物理路径和我的应用程序工作主题(如普通文件夹)。 但在NetCore中,我们将Kestrel和IIS用作Kestrel无法识别的代理和虚拟目录。我使用此代码,但不在函数中工作。在配置函数中编写此部分 app.UseFileServer(new FileServerOptions { FileProvide

在ASP.NET framework 4.8及以下版本中,web应用程序使用IIS处理和显示数据。当我们需要使用其他资源(如文件夹和网络资源)时,我们可以轻松地在IIS中创建虚拟目录,并映射到物理路径和我的应用程序工作主题(如普通文件夹)。 但在NetCore中,我们将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文件夹内创建目录。那么,我必须怎么做?

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


您可以尝试将iis\u iusr、iusr或iis AppPool权限分配给要在其中创建目录的文件夹。

显示实际错误页面。