将txt文件和rar文件都放到 wwwroot 目录下,会发现前者可以正常下载而后者不行。其实是需要在初始化的地方进行设置:
builder.WebHost.UseKestrel(option =>
{
option.ListenAnyIP(config.Port);
});
WebApplication app = builder.Build();
var httpContextAccessor = app.Services.GetRequiredService<IHttpContextAccessor>();
xHttpContext.Configure(httpContextAccessor);
//app.UseStaticFiles().UseRouting().xUseMyCustomMiddleware();
app.UseStaticFiles(new StaticFileOptions
{
ServeUnknownFileTypes = true,
DefaultContentType = "application/octet-stream",
//ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string, string>
//{
// 【西西 2024-08-06 140916】这种方式就是一个一个的配,可以动态化。也可以像上面那样一刀切。
// { ".7z", "" }
//}),
}).UseRouting().xUseMyCustomMiddleware();
InitRoutes(app);
BizGlobal.Init();
app.Run();
标签:core,httpContextAccessor,option,文件,app,默认,new,aspnet From: https://www.cnblogs.com/wenzd/p/18345031