How does ASP.NET vNext handle caching, compression, and MimeMap in config.json?

In previous versions, all of these parameters could be added and changed in the Web.Config file using the following code:

<staticContent> <mimeMap fileExtension=".webp" mimeType="image/webp" /> <!-- Caching --> <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="96:00:00" /> </staticContent> <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"> <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" /> <dynamicTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="message/*" enabled="true" /> <add mimeType="application/javascript" enabled="true" /> <add mimeType="*/*" enabled="false" /> </dynamicTypes> <staticTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="message/*" enabled="true" /> <add mimeType="application/javascript" enabled="true" /> <add mimeType="*/*" enabled="false" /> </staticTypes> </httpCompression> <urlCompression doStaticCompression="true" doDynamicCompression="true"/> 

However, if Web.Config is no longer in ASP.NET vNext, how do you configure these settings? I searched net and ASP.NET Github repo, but didn't come across anything - any ideas?

+7
caching asp.net-mvc asp.net-core compression
Feb 25 '15 at 12:49
source share
1 answer

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 ... }); ... } 
+8
Feb 25 '15 at 21:12
source share



All Articles