MIME一般在web服务器比如iis或nginx中添加。.NET Core在linux上使用的是Kestrel Web服务器,如果不用nginx反向代理,可以在代码中添加。
打开Startup.cs,找到Configure方法,在里面添加
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
//------以下添加MIME---------
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".m3u8"] = "application/x-mpegURL"; //m3u8的MIME
provider.Mappings[".ts"] = "video/MP2TL"; //.ts的MIME
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = provider
});
//------以上添加MIME---------
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}