Skip to content

Instantly share code, notes, and snippets.

@TheEskhaton
Created April 1, 2019 13:07
Show Gist options
  • Save TheEskhaton/799aca469c281a43570ed4ee1a0523be to your computer and use it in GitHub Desktop.
Save TheEskhaton/799aca469c281a43570ed4ee1a0523be to your computer and use it in GitHub Desktop.
kentico media module
// Registers the custom module into the system
[assembly: RegisterModule(typeof(AzureMediaModule))]
public class AzureMediaModule : Module
{
// Module class constructor, the system registers the module under the name "AzureMediaModule"
public AzureMediaModule()
: base("AzureMediaModule")
{
}
// Contains initialization code that is executed when the application starts
protected override void OnInit()
{
base.OnInit();
if (bool.TryParse(WebConfigurationManager.AppSettings.Get("AzureStorageEnabled"), out bool enabled)
&& enabled)
{
// Creates a new StorageProvider instance for Azure
var mediaProvider = StorageProvider.CreateAzureStorageProvider();
// Specifies the target container
mediaProvider.CustomRootPath = WebConfigurationManager.AppSettings.Get("AzureStorageMediaRootPath");
// Makes the container publicly accessible
mediaProvider.PublicExternalFolderObject = true;
// Maps a directory to the provider
StorageHelper.MapStoragePath($"~/{SiteContext.CurrentSiteName}/media/", mediaProvider);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment