.net6 访问静态文件 ContentType MIME
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"
});
}
留待后查,同时方便他人
联系我:renhanlinbsl@163.com
联系我:renhanlinbsl@163.com