As the comments on "agua from mars" say, if you use IIS, you can use static processing of IIS files, in which case you can use the <system.webServer> section in the web.config file, and this will work as always did.
If you are using ASP.NET 5 StaticFileMiddleware, then it has its own MIME mappings, which are included as part of FileExtensionContentTypeProvider . StaticFileMiddleware has StaticFileOptions , which you can use to configure it when initializing in Startup.cs . In this parameter class, you can set the content provider. You can create an instance of the default content provider, and then simply set up a mapping dictionary or write a full mapping from scratch (not recommended).
ASP.NET Kernel Mappings - mime:
If the extended set of file types that you provide for the entire site does not change, you can configure one instance of the ContentTypeProvider class, and then use DI to use it when serving static files, for example
public void ConfigureServices(IServiceCollection services) { ... services.AddInstance<IContentTypeProvider>( new FileExtensionConentTypeProvider( new Dictionary<string, string>( // Start with the base mappings new FileExtensionContentTypeProvider().Mappings, // Extend the base dictionary with your custom mappings StringComparer.OrdinalIgnoreCase) { { ".nmf", "application/octet-stream" } { ".pexe", "application/x-pnal" }, { ".mem", "application/octet-stream" }, { ".res", "application/octet-stream" } } ) ); ... } public void Configure( IApplicationBuilder app, IContentTypeProvider contentTypeProvider) { ... app.UseStaticFiles(new StaticFileOptions() { ContentTypeProvider = contentTypeProvider ... }); ... }
Eilon Feb 25 '15 at 21:12 2015-02-25 21:12
source share