静态文件访问
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}");
}
});
注意项:此种模式目录下可以找到配置的静态文件,没有回报错