.net core UseStaticFiles访问静态文件打不开.log格式
程序员文章站
2022-07-09 21:10:57
...
var cacheMaxAge = 64800;
var provider = new FileExtensionContentTypeProvider();
//添加之后能够识别.log格式
provider.Mappings[".log"] = "text/plain";
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"log")),
RequestPath = "/log",
ContentTypeProvider = provider,
OnPrepareResponse = ctx =>
{
// using Microsoft.AspNetCore.Http;
ctx.Context.Response.Headers.Append(
"Cache-Control", $"public, max-age={cacheMaxAge}");
}
});
注意项:此种模式目录下可以找到配置的静态文件,没有回报错