diff --git a/src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs b/src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs index a562df7d4..46afcbc9c 100644 --- a/src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs +++ b/src/ImageProcessor.Web/Configuration/ImageProcessorConfiguration.cs @@ -281,7 +281,7 @@ namespace ImageProcessor.Web.Configuration return settings; } -#endregion + #endregion #region ImageServices /// @@ -345,7 +345,19 @@ namespace ImageProcessor.Web.Configuration throw new TypeLoadException("Couldn't load IImageService: " + config.Type); } - this.GraphicsProcessors.Add(Activator.CreateInstance(type) as IWebGraphicsProcessor); + IImageService imageService = Activator.CreateInstance(type) as IImageService; + if (!string.IsNullOrWhiteSpace(config.Prefix)) + { + if (!string.IsNullOrWhiteSpace(config.Prefix)) + { + if (imageService != null) + { + imageService.Prefix = config.Prefix; + } + } + } + + this.ImageServices.Add(imageService); } // Add the available settings. diff --git a/src/ImageProcessor.Web/Configuration/ImageSecuritySection.cs b/src/ImageProcessor.Web/Configuration/ImageSecuritySection.cs index 60fa113fa..dd47c9ac5 100644 --- a/src/ImageProcessor.Web/Configuration/ImageSecuritySection.cs +++ b/src/ImageProcessor.Web/Configuration/ImageSecuritySection.cs @@ -68,9 +68,9 @@ namespace ImageProcessor.Web.Configuration public class ServiceElement : ConfigurationElement { /// - /// Gets or sets the name of the plugin file. + /// Gets or sets the name of the service. /// - /// The name of the plugin. + /// The name of the service. [ConfigurationProperty("name", DefaultValue = "", IsRequired = true)] public string Name { @@ -80,9 +80,21 @@ namespace ImageProcessor.Web.Configuration } /// - /// Gets or sets the type of the service file. + /// Gets or sets the prefix of the service. /// - /// The full Type definition of the plugin + /// The prefix of the service. + [ConfigurationProperty("prefix", DefaultValue = "", IsRequired = false)] + public string Prefix + { + get { return (string)this["prefix"]; } + + set { this["prefix"] = value; } + } + + /// + /// Gets or sets the type of the service. + /// + /// The full Type definition of the service [ConfigurationProperty("type", DefaultValue = "", IsRequired = true)] public string Type { diff --git a/src/ImageProcessor.Web/Configuration/Resources/security.config b/src/ImageProcessor.Web/Configuration/Resources/security.config index 1e415c0d3..5326f270f 100644 --- a/src/ImageProcessor.Web/Configuration/Resources/security.config +++ b/src/ImageProcessor.Web/Configuration/Resources/security.config @@ -1,7 +1,7 @@ - + diff --git a/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs b/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs index 9927e3330..d918e0ffe 100644 --- a/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs +++ b/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs @@ -530,7 +530,7 @@ namespace ImageProcessor.Web.HttpModules string path = request.Path; foreach (IImageService service in services) { - string key = service.Key; + string key = service.Prefix; if (!string.IsNullOrWhiteSpace(key) && path.EndsWith(key, StringComparison.InvariantCultureIgnoreCase)) { imageService = service; @@ -545,7 +545,7 @@ namespace ImageProcessor.Web.HttpModules // Return the file based service if (ImageHelpers.IsValidImageExtension(path)) { - return services.FirstOrDefault(s => string.IsNullOrWhiteSpace(s.Key)); + return services.FirstOrDefault(s => string.IsNullOrWhiteSpace(s.Prefix)); } return null; diff --git a/src/ImageProcessor.Web/Services/IImageService.cs b/src/ImageProcessor.Web/Services/IImageService.cs index 23746cea0..3488f30cf 100644 --- a/src/ImageProcessor.Web/Services/IImageService.cs +++ b/src/ImageProcessor.Web/Services/IImageService.cs @@ -20,12 +20,12 @@ namespace ImageProcessor.Web.Services public interface IImageService { /// - /// Gets the key for the given implementation. + /// Gets or sets the prefix for the given implementation. /// /// This value is used as a prefix for any image requests that should use this service. /// /// - string Key { get; } + string Prefix { get; set; } /// /// Gets a value indicating whether the image service requests files from diff --git a/src/ImageProcessor.Web/Services/LocalFileImageService.cs b/src/ImageProcessor.Web/Services/LocalFileImageService.cs index 3a95d558a..c9726b2eb 100644 --- a/src/ImageProcessor.Web/Services/LocalFileImageService.cs +++ b/src/ImageProcessor.Web/Services/LocalFileImageService.cs @@ -22,16 +22,26 @@ namespace ImageProcessor.Web.Services public class LocalFileImageService : IImageService { /// - /// Gets the key for the given implementation. + /// The prefix for the given implementation. + /// + private string prefix = string.Empty; + + /// + /// Gets or sets the prefix for the given implementation. /// /// This value is used as a prefix for any image requests that should use this service. /// /// - public string Key + public string Prefix { get { - return string.Empty; + return this.prefix; + } + + set + { + this.prefix = value; } } diff --git a/src/ImageProcessor.Web/Services/RemoteImageService.cs b/src/ImageProcessor.Web/Services/RemoteImageService.cs index fadf68c23..acebdf5d0 100644 --- a/src/ImageProcessor.Web/Services/RemoteImageService.cs +++ b/src/ImageProcessor.Web/Services/RemoteImageService.cs @@ -24,6 +24,11 @@ namespace ImageProcessor.Web.Services /// public class RemoteImageService : IImageService { + /// + /// The prefix for the given implementation. + /// + private string prefix = "remote.axd"; + /// /// Initializes a new instance of the class. /// @@ -39,16 +44,21 @@ namespace ImageProcessor.Web.Services } /// - /// Gets the key for the given implementation. + /// Gets or sets the prefix for the given implementation. /// /// This value is used as a prefix for any image requests that should use this service. /// /// - public string Key + public string Prefix { get { - return "remote.axd"; + return this.prefix; + } + + set + { + this.prefix = value; } } diff --git a/src/TestWebsites/MVC/config/imageprocessor/security.config b/src/TestWebsites/MVC/config/imageprocessor/security.config index cd54dde6a..b49f89854 100644 --- a/src/TestWebsites/MVC/config/imageprocessor/security.config +++ b/src/TestWebsites/MVC/config/imageprocessor/security.config @@ -2,7 +2,7 @@ - +