asp .net core静态文件资源的深入讲解(2)

因为provider.Mappings[".htm3"] = "text/html"; ,.htm3被映射成了text/html,那么客户端就按照这种格式处理。所以模板引擎就可以多样性,有兴趣自己也可以去设计。

这就是媒体类型映射。

如果是媒体类型未知的情况下,那么可以这样:

app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "Static")), RequestPath = "/static", OnPrepareResponse = ctx => { ctx.Context.Response.Headers.Append("cache-control", $"public,max-age={cacheMaxAge}"); }, ServeUnknownFileTypes = true, DefaultContentType = "image/png" } );

ServeUnknownFileTypes true

DefaultContentType "image/png" 让客户端按照图片处理。

asp .net core静态文件资源的深入讲解

但是官方给了建议。

启用 ServeUnknownFileTypes 会形成安全隐患。 它默认处于禁用状态,不建议使用。

FileExtensionContentTypeProvider 提供了更安全的替代方法来提供含非标准扩展名的文件。

总结

到此这篇关于asp .net core静态文件资源的文章就介绍到这了,更多相关asp .net core静态文件资源内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wxgdxf.html