HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In
GitHubNuGetDev CommunityDoc feedback

File Providers

Describes how to use file provider to map files to virtual paths in the site.

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.

In addition to ASP.NET Core, two different file providers ContentRootFileProvider and WebRootFileProvider that are available on IWebHostFileProvider Optimizely Content Management System (CMS) also registers one instance of a ICompositeFileProvider that acts as a façade over the built-in provider but also supports additional provider registration. You can register custom file providers to the composite file provider through CompositeFileProviderOptions. The composite file provider is used to resolve resources from shell modules. The composite file provider is registered in the DI container.

The MappingPhysicalFileProvider is used to map in physical files, not 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")));                  
  });

CMS also contains a zip archive file provider you can use if files are stored in a zip archive. 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.