.Net 6.0 在Linux部署后特殊格式静态文件404
2023-11-04 16:59 古兆洋 阅读(30) 评论(0) 编辑 收藏 举报转自:https://blog.csdn.net/wxz19960412/article/details/131085819
只需要添加如下代码即可:
1 app.UseStaticFiles(); 2 3 app.UseStaticFiles(new StaticFileOptions 4 { 5 ServeUnknownFileTypes = true //设置不限制content-type 6 }); 7 8 //添加特殊类型 9 var provider = new FileExtensionContentTypeProvider(new Dictionary<string, string> { 10 {".step","application/octet-stream" }, 11 {".stp","application/octet-stream" }, 12 }); 13 14 15 app.UseStaticFiles(new StaticFileOptions 16 { 17 FileProvider = new PhysicalFileProvider(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FILES")), 18 ContentTypeProvider=provider, 19 RequestPath = "/FILES" 20 21 });