Loading...
Area: Optimizely CMS
Applies to versions: 12 and higher
Other versions:

File Providers

Recommended reading 
Note: This documentation is for the preview version of the upcoming release of CMS 12/Commerce 14/Search & Navigation 14. Features included here might not be complete, and might be changed before becoming available in the public release. This documentation is provided for evaluation purposes only.

Optimizely products use File Providers to map files to virtual paths in the site. Protected modules use file providers so you can have a single physical location for the modules even though the virtual path on the site is configurable.

Configuring a File Provider

In addition to ASP.NET Core:s two different file providers ContentRootFileProvider and WebRootFileProvider that are available on IWebHostFileProvider CMS also registers one instance of a ICompositeFileProvider that acts as a facade over the built-in provider but also support registration of additional providers. You can register custom file providers to the composite file provider through CompositeFileProviderOptions. The composite file provider is used for example to resolve resources from shell modules. The composite file provider is registered in the DI container.

MappingPhysicalFileProvider

The MappingPhysicalFileProvider is used to map in physical files that are not located directly under the application root. The following example shows a registration of a MappingPhysicalFileProvider:

serviceCollection.Configure<CompositeFileProviderOptions>(c =>
{
  c.BasePathFileProviders.Add(new MappingPhysicalFileProvider("/SomeVirtualPath", string.Empty,
    Path.Combine(webHostEnvironment.ContentRootPath, @"SomePhysicalFolder")));                  
});

ZipArchiveFileProvider

CMS also contains a zip archive file provider that you can use if files are stored in a zip archive.

Shell modules

When shell modules are registered, a file provider is also automatically registered for the shell module. If the resources are packaged in a zip archive, an instance of ZipArchiveFileProvider is registered.

Do you find this information helpful? Please log in to provide feedback.

Last updated: Jul 02, 2021

Recommended reading