asp .net core静态文件资源的深入讲解
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" 让客户端按照图片处理。 但是官方给了建议。 启用 ServeUnknownFileTypes 会形成安全隐患。 它默认处于禁用状态,不建议使用。 FileExtensionContentTypeProvider 提供了更安全的替代方法来提供含非标准扩展名的文件。 (编辑:ASP站长) 【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。 |
-
无相关信息