private static void InjectResourcePath(WebApplication app, string path, string requestPath)
{
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".prj"] = "application/octet-stream";
provider.Mappings[".sgy"] = "application/octet-stream";
//发布时服务器注册静态资源
string fileUpload = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
if (!Directory.Exists(fileUpload))
{
Directory.CreateDirectory(fileUpload);
}
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(fileUpload),
RequestPath = requestPath,
ContentTypeProvider = provider,
//不识别的文件是否处理
ServeUnknownFileTypes = true,
//默认方式
DefaultContentType = "application/octet-stream"
//DefaultContentType = "application/x-msdownload"
});
}
标签:fileUpload,ContentType,stream,octet,new,application,MIME,provider,net6
From: https://www.cnblogs.com/ives/p/18540308