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