HomeDev GuideRecipesAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

File providers and virtual paths

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

File providers let you map physical files to virtual paths, so you can store resources in a single location and serve them under any configurable path on your site. Optimizely CMS registers a composite file provider that supports custom provider registration for shell modules and other resources. For background on ASP.NET Core file providers, see the Microsoft documentation.

Composite file provider

ASP.NET Core provides two file providers, ContentRootFileProvider and WebRootFileProvider, available on IWebHostEnvironment. Optimizely Content Management System (CMS) also registers an ICompositeFileProvider instance that wraps the built-in providers and supports additional provider registration.

Register custom file providers through CompositeFileProviderOptions. The composite file provider resolves resources from shell modules. CMS registers the composite file provider in the dependency injection (DI) container.

Mapping physical file provider

Use MappingPhysicalFileProvider to map physical files from locations outside the application root. The following example registers a MappingPhysicalFileProvider:

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

Zip archive file provider

ZipArchiveFileProvider serves files stored in a zip archive. When you register a shell module, CMS automatically registers a file provider for it. If the resources are packaged in a zip archive, CMS registers a ZipArchiveFileProvider instance.