asp.net-core - 在 ASP.NET Core 3.1 中使用虚拟目录
问题描述
在 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
。那么,我必须做什么?
解决方案
您收到此错误是因为 iis 默认帐户没有足够的权限来访问该文件夹。
您可以尝试将 iis_iusrs 、 iusr 或 IIS AppPool<myappoolname> 权限分配给要在其中创建目录的文件夹。
推荐阅读
- oracle - 删除字符串末尾的字符
- r - 吉特图上的数据签名
- sql - 如何为 SQL 表制作自定义属性
- r - R中用于臭氧数据集的选择函数问题
- javascript - 发送没有按钮事件的文件
- file - 如果我想将项目放在另一个 GitHub 存储库中并将提交推送到那里,从 GitHub 下载的项目中删除一些文件?
- javascript - 当用户将鼠标悬停快速移动到下拉菜单时,下拉菜单在引导程序中闪烁
- c++ - 在 C++ 中从 zip 文件写入文件
- oracle - 在 Oracle SQL 中,DELETE 语句是否会由 COMMIT 在其后调用的过程中提交?
- regex - 我可以使用正则表达式来指定要与值进行比较的数组的索引吗?