/// <summary> /// Overridable method to execute when All resolvers have been initialized but resolution is not /// frozen so they can be modified in this method /// </summary> /// <param name="umbracoApplication">The current <see cref="UmbracoApplicationBase"/></param> /// <param name="applicationContext">The Umbraco <see cref="ApplicationContext"/> for the current application.</param> protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { bool disable = ConfigurationManager.AppSettings[DisableVirtualPathProviderKey] != null && ConfigurationManager.AppSettings[DisableVirtualPathProviderKey] .Equals("true", StringComparison.InvariantCultureIgnoreCase); IFileSystem fileSystem = FileSystemProviderManager.Current.GetUnderlyingFileSystemProvider(Constants.DefaultMediaRoute); bool isAzureBlobFileSystem = fileSystem is AzureBlobFileSystem; if (!disable && isAzureBlobFileSystem) { AzureFileSystem azureFileSystem = ((AzureBlobFileSystem)fileSystem).FileSystem; // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression if (azureFileSystem.UseDefaultRoute) { FileSystemVirtualPathProvider.ConfigureMedia(Constants.DefaultMediaRoute); } else { FileSystemVirtualPathProvider.ConfigureMedia(azureFileSystem.ContainerName); } } base.ApplicationStarting(umbracoApplication, applicationContext); }
/// <summary> /// Configures the virtual path provider. /// </summary> /// <param name="pathPrefix"> /// The path prefix. /// </param> /// <typeparam name="TProviderTypeFilter"> /// The provider type filter. /// </typeparam> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="pathPrefix"/> is null. /// </exception> public static void Configure <TProviderTypeFilter>(string pathPrefix = "media") where TProviderTypeFilter : FileSystemWrapper { if (string.IsNullOrEmpty(pathPrefix)) { throw new ArgumentNullException("pathPrefix"); } Lazy <IFileSystem> fileSystem = new Lazy <IFileSystem>(() => FileSystemProviderManager.Current.GetFileSystemProvider <TProviderTypeFilter>()); FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider(pathPrefix, fileSystem); HostingEnvironment.RegisterVirtualPathProvider(provider); }
/// <summary> /// Overridable method to execute when All resolvers have been initialized but resolution is not /// frozen so they can be modified in this method /// </summary> /// <param name="umbracoApplication">The current <see cref="UmbracoApplicationBase"/></param> /// <param name="applicationContext">The Umbraco <see cref="ApplicationContext"/> for the current application.</param> protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { bool disable = ConfigurationManager.AppSettings[DisableVirtualPathProviderKey] != null && ConfigurationManager.AppSettings[DisableVirtualPathProviderKey] .Equals("true", StringComparison.InvariantCultureIgnoreCase); IFileSystem fileSystem = FileSystemProviderManager.Current.GetUnderlyingFileSystemProvider("media"); bool isAzureBlobFileSystem = fileSystem.GetType() == typeof(AzureBlobFileSystem); if (!disable && isAzureBlobFileSystem) { FileSystemVirtualPathProvider.ConfigureMedia(); } base.ApplicationStarting(umbracoApplication, applicationContext); }
/// <summary> /// Configures the virtual path provider. /// </summary> /// <param name="pathPrefix"> /// The path prefix. /// </param> /// <typeparam name="TProviderTypeFilter"> /// The provider type filter. /// </typeparam> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="pathPrefix"/> is null. /// </exception> public static void Configure <TProviderTypeFilter>(string pathPrefix = Constants.DefaultMediaRoute) where TProviderTypeFilter : FileSystemWrapper { if (string.IsNullOrEmpty(pathPrefix)) { throw new ArgumentNullException(nameof(pathPrefix)); } Lazy <IFileSystem> fileSystem = new Lazy <IFileSystem>(() => FileSystemProviderManager.Current.GetFileSystemProvider <TProviderTypeFilter>()); FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider(pathPrefix, fileSystem); // The standard HostingEnvironment.RegisterVirtualPathProvider(virtualPathProvider) method is ignored when // BuildManager.IsPrecompiledApp is true so we have to use reflection when registering the provider. if (!BuildManager.IsPrecompiledApp) { HostingEnvironment.RegisterVirtualPathProvider(provider); } else { // Gets the private _theHostingEnvironment reference. HostingEnvironment hostingEnvironmentInstance = (HostingEnvironment)typeof(HostingEnvironment) .InvokeMember("_theHostingEnvironment", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null); if (hostingEnvironmentInstance == null) { return; } // Get the static internal MethodInfo for RegisterVirtualPathProviderInternal method. MethodInfo methodInfo = typeof(HostingEnvironment) .GetMethod("RegisterVirtualPathProviderInternal", BindingFlags.NonPublic | BindingFlags.Static); if (methodInfo == null) { return; } // Invoke RegisterVirtualPathProviderInternal method with one argument which is the instance of our own provider. methodInfo.Invoke(hostingEnvironmentInstance, new object[] { provider }); } }