diff --git a/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj b/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj
index 6c01a8bcc..047451f26 100644
--- a/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj
+++ b/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj
@@ -51,6 +51,10 @@
..\..\packages\Microsoft.Bcl.Async.1.0.165\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll
+
+ True
+ ..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll
+
@@ -68,6 +72,7 @@
+
@@ -86,6 +91,12 @@
ImageHelpers.cs
+
+ ResourceHelpers.cs
+
+
+ StartUp.cs
+
@@ -98,6 +109,15 @@
+
+ Config\Resources\cache.config
+
+
+ Config\Resources\processing.config
+
+
+ Config\Resources\security.config
+
Designer
diff --git a/src/ImageProcessor.Web/NET4/packages.config b/src/ImageProcessor.Web/NET4/packages.config
index 86eb14bb5..18cb40932 100644
--- a/src/ImageProcessor.Web/NET4/packages.config
+++ b/src/ImageProcessor.Web/NET4/packages.config
@@ -3,4 +3,5 @@
+
\ No newline at end of file
diff --git a/src/ImageProcessor.Web/NET45/Config/ImageCacheSection.cs b/src/ImageProcessor.Web/NET45/Config/ImageCacheSection.cs
index b4b74f45d..6bda16a44 100644
--- a/src/ImageProcessor.Web/NET45/Config/ImageCacheSection.cs
+++ b/src/ImageProcessor.Web/NET45/Config/ImageCacheSection.cs
@@ -1,16 +1,22 @@
-// -----------------------------------------------------------------------
+// --------------------------------------------------------------------------------------------------------------------
//
-// Copyright (c) James South.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) James South.
+// Licensed under the Apache License, Version 2.0.
//
-// -----------------------------------------------------------------------
+//
+// Represents an image cache section within a configuration file.
+//
+// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Web.Config
{
#region Using
using System.Configuration;
+ using System.IO;
+ using System.Xml;
using ImageProcessor.Extensions;
+ using ImageProcessor.Web.Helpers;
#endregion
@@ -24,7 +30,7 @@ namespace ImageProcessor.Web.Config
///
/// The name of the cache folder.
[ConfigurationProperty("virtualPath", DefaultValue = "~/app_data/cache", IsRequired = true)]
- [StringValidator(MinLength = 3, MaxLength = 200)]
+ [StringValidator(MinLength = 3, MaxLength = 256)]
public string VirtualPath
{
get
@@ -45,7 +51,7 @@ namespace ImageProcessor.Web.Config
///
/// The maximum number of days to store an image in the cache.
/// Defaults to 28 if not set.
- [ConfigurationProperty("maxDays", DefaultValue = "28", IsRequired = false)]
+ [ConfigurationProperty("maxDays", DefaultValue = "365", IsRequired = false)]
[IntegerValidator(ExcludeRange = false, MinValue = 0)]
public int MaxDays
{
@@ -73,7 +79,12 @@ namespace ImageProcessor.Web.Config
return imageCacheSection;
}
- return new ImageCacheSection();
+ string section = ResourceHelpers.ResourceAsString("ImageProcessor.Web.Config.Resources.cache.config");
+ XmlReader reader = new XmlTextReader(new StringReader(section));
+ imageCacheSection = new ImageCacheSection();
+ imageCacheSection.DeserializeSection(reader);
+
+ return imageCacheSection;
}
}
}
diff --git a/src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs b/src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs
index 1b0ed5952..7111521af 100644
--- a/src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs
+++ b/src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs
@@ -13,7 +13,10 @@ namespace ImageProcessor.Web.Config
{
#region Using
using System.Configuration;
+ using System.IO;
using System.Linq;
+ using System.Xml;
+ using ImageProcessor.Web.Helpers;
#endregion
///
@@ -69,7 +72,12 @@ namespace ImageProcessor.Web.Config
return imageProcessingSection;
}
- return new ImageProcessingSection();
+ string section = ResourceHelpers.ResourceAsString("ImageProcessor.Web.Config.Resources.processing.config");
+ XmlReader reader = new XmlTextReader(new StringReader(section));
+ imageProcessingSection = new ImageProcessingSection();
+ imageProcessingSection.DeserializeSection(reader);
+
+ return imageProcessingSection;
}
#endregion
diff --git a/src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs b/src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs
index 4fbc08b47..d5f457798 100644
--- a/src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs
+++ b/src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs
@@ -13,12 +13,9 @@ namespace ImageProcessor.Web.Config
#region Using
using System;
using System.Collections.Generic;
- using System.IO;
using System.Linq;
using System.Reflection;
- using System.Text;
using System.Web.Compilation;
-
using ImageProcessor.Processors;
#endregion
@@ -300,7 +297,7 @@ namespace ImageProcessor.Web.Config
.SelectMany(s => s.GetTypes())
.Where(t => t != null && type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract)
.ToList();
-
+
// Create them and add.
this.GraphicsProcessors = availableTypes.Select(x => (Activator.CreateInstance(x) as IGraphicsProcessor)).ToList();
@@ -310,7 +307,7 @@ namespace ImageProcessor.Web.Config
processor.Settings = this.GetPluginSettings(processor.GetType().Name);
}
}
- catch (ReflectionTypeLoadException ex)
+ catch (ReflectionTypeLoadException)
{
this.LoadGraphicsProcessorsFromConfiguration();
}
@@ -352,4 +349,4 @@ namespace ImageProcessor.Web.Config
}
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/src/ImageProcessor.Web/NET45/Config/ImageSecuritySection.cs b/src/ImageProcessor.Web/NET45/Config/ImageSecuritySection.cs
index dac3dd84e..824cf8277 100644
--- a/src/ImageProcessor.Web/NET45/Config/ImageSecuritySection.cs
+++ b/src/ImageProcessor.Web/NET45/Config/ImageSecuritySection.cs
@@ -13,6 +13,11 @@ namespace ImageProcessor.Web.Config
#region Using
using System;
using System.Configuration;
+ using System.IO;
+ using System.Xml;
+
+ using ImageProcessor.Web.Helpers;
+
#endregion
///
@@ -55,8 +60,8 @@ namespace ImageProcessor.Web.Config
/// Gets or sets the maximum allowed remote file size in bytes for the application.
///
/// The maximum number of days to store an image in the cache.
- /// Defaults to 524288 (512kb) if not set.
- [ConfigurationProperty("maxBytes", DefaultValue = "524288", IsRequired = true)]
+ /// Defaults to 4194304 (4Mb) if not set.
+ [ConfigurationProperty("maxBytes", DefaultValue = "4194304", IsRequired = true)]
public int MaxBytes
{
get
@@ -111,7 +116,12 @@ namespace ImageProcessor.Web.Config
return imageSecuritySection;
}
- return new ImageSecuritySection();
+ string section = ResourceHelpers.ResourceAsString("ImageProcessor.Web.Config.Resources.security.config");
+ XmlReader reader = new XmlTextReader(new StringReader(section));
+ imageSecuritySection = new ImageSecuritySection();
+ imageSecuritySection.DeserializeSection(reader);
+
+ return imageSecuritySection;
}
#endregion
diff --git a/src/ImageProcessor.Web/NET45/Config/Resources/cache.config b/src/ImageProcessor.Web/NET45/Config/Resources/cache.config
new file mode 100644
index 000000000..1caab6358
--- /dev/null
+++ b/src/ImageProcessor.Web/NET45/Config/Resources/cache.config
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/ImageProcessor.Web/NET45/Config/Resources/processing.config b/src/ImageProcessor.Web/NET45/Config/Resources/processing.config
new file mode 100644
index 000000000..0cb384b96
--- /dev/null
+++ b/src/ImageProcessor.Web/NET45/Config/Resources/processing.config
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/ImageProcessor.Web/NET45/Config/Resources/security.config b/src/ImageProcessor.Web/NET45/Config/Resources/security.config
new file mode 100644
index 000000000..99cd3d3ff
--- /dev/null
+++ b/src/ImageProcessor.Web/NET45/Config/Resources/security.config
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/src/ImageProcessor.Web/NET45/Helpers/ResourceHelpers.cs b/src/ImageProcessor.Web/NET45/Helpers/ResourceHelpers.cs
new file mode 100644
index 000000000..fe8dc523b
--- /dev/null
+++ b/src/ImageProcessor.Web/NET45/Helpers/ResourceHelpers.cs
@@ -0,0 +1,56 @@
+// --------------------------------------------------------------------------------------------------------------------
+//
+// Copyright (c) James South.
+// Licensed under the Apache License, Version 2.0.
+//
+//
+// Provides helper methods for working with resources.
+//
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace ImageProcessor.Web.Helpers
+{
+ using System.IO;
+ using System.Reflection;
+ using System.Text;
+
+ ///
+ /// Provides helper methods for working with resources.
+ ///
+ public class ResourceHelpers
+ {
+ ///
+ /// Converts an assembly resource into a string.
+ ///
+ ///
+ /// The resource.
+ ///
+ ///
+ /// The assembly.
+ ///
+ ///
+ /// The character encoding to return the resource in.
+ ///
+ ///
+ /// The .
+ ///
+ public static string ResourceAsString(string resource, Assembly assembly = null, Encoding encoding = null)
+ {
+ assembly = assembly ?? Assembly.GetExecutingAssembly();
+ encoding = encoding ?? Encoding.UTF8;
+
+ using (MemoryStream ms = new MemoryStream())
+ {
+ using (Stream manifestResourceStream = assembly.GetManifestResourceStream(resource))
+ {
+ if (manifestResourceStream != null)
+ {
+ manifestResourceStream.CopyTo(ms);
+ }
+ }
+
+ return encoding.GetString(ms.GetBuffer()).Replace('\0', ' ').Trim();
+ }
+ }
+ }
+}
diff --git a/src/ImageProcessor.Web/NET45/Helpers/StartUp.cs b/src/ImageProcessor.Web/NET45/Helpers/StartUp.cs
new file mode 100644
index 000000000..81310e620
--- /dev/null
+++ b/src/ImageProcessor.Web/NET45/Helpers/StartUp.cs
@@ -0,0 +1,31 @@
+// --------------------------------------------------------------------------------------------------------------------
+//
+// Copyright (c) James South.
+// Licensed under the Apache License, Version 2.0.
+//
+//
+// Provides methods to handle startup events.
+//
+// --------------------------------------------------------------------------------------------------------------------
+
+[assembly: System.Web.PreApplicationStartMethod(typeof(ImageProcessor.Web.Helpers.StartUp), "PreApplicationStart")]
+
+namespace ImageProcessor.Web.Helpers
+{
+ using ImageProcessor.Web.HttpModules;
+ using Microsoft.Web.Infrastructure.DynamicModuleHelper;
+
+ ///
+ /// Provides methods to handle startup events.
+ ///
+ public static class StartUp
+ {
+ ///
+ /// The pre application start.
+ ///
+ public static void PreApplicationStart()
+ {
+ DynamicModuleUtility.RegisterModule(typeof(ImageProcessingModule));
+ }
+ }
+}
diff --git a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
index ae4700ba2..7d7024584 100644
--- a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
+++ b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
@@ -31,6 +31,9 @@ namespace ImageProcessor.Web.HttpModules
using ImageProcessor.Web.Caching;
using ImageProcessor.Web.Config;
using ImageProcessor.Web.Helpers;
+
+ using Microsoft.Web.Infrastructure.DynamicModuleHelper;
+
#endregion
///
@@ -49,11 +52,6 @@ namespace ImageProcessor.Web.HttpModules
///
private static readonly Regex PresetRegex = new Regex(@"preset=[^&]*", RegexOptions.Compiled);
- ///
- /// The value to prefix any remote image requests with to ensure they get captured.
- ///
- private static readonly string RemotePrefix = ImageProcessorConfig.Instance.RemotePrefix;
-
///
/// The assembly version.
///
@@ -64,6 +62,11 @@ namespace ImageProcessor.Web.HttpModules
///
private static readonly Dictionary SemaphoreSlims = new Dictionary();
+ ///
+ /// The value to prefix any remote image requests with to ensure they get captured.
+ ///
+ private static string remotePrefix;
+
///
/// A value indicating whether this instance of the given entity has been disposed.
///
@@ -109,17 +112,17 @@ namespace ImageProcessor.Web.HttpModules
///
public void Init(HttpApplication context)
{
-#if NET45
+ if (remotePrefix == null)
+ {
+ remotePrefix = ImageProcessorConfig.Instance.RemotePrefix;
+ }
+#if NET45
EventHandlerTaskAsyncHelper wrapper = new EventHandlerTaskAsyncHelper(this.PostAuthorizeRequest);
context.AddOnPostAuthorizeRequestAsync(wrapper.BeginEventHandler, wrapper.EndEventHandler);
-
#else
-
context.PostAuthorizeRequest += this.PostAuthorizeRequest;
-
#endif
-
context.PreSendRequestHeaders += this.ContextPreSendRequestHeaders;
}
@@ -264,7 +267,7 @@ namespace ImageProcessor.Web.HttpModules
HttpRequest request = context.Request;
// Fixes issue 10.
- bool isRemote = request.Path.EndsWith(RemotePrefix, StringComparison.OrdinalIgnoreCase);
+ bool isRemote = request.Path.EndsWith(remotePrefix, StringComparison.OrdinalIgnoreCase);
string requestPath = string.Empty;
string queryString = string.Empty;
diff --git a/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj b/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj
index cdb14683e..10b2f0923 100644
--- a/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj
+++ b/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj
@@ -32,6 +32,10 @@
4
+
+ True
+ ..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll
+
@@ -53,6 +57,8 @@
+
+
@@ -66,6 +72,16 @@
ImageProcessor
+
+
+ Designer
+
+
+ Designer
+
+
+
+
-
+
-
-
+
+
-
+
@@ -41,16 +41,9 @@
-
-
-
-
-
-
-
@@ -60,8 +53,6 @@
-
-
-
+
diff --git a/src/packages/repositories.config b/src/packages/repositories.config
index da0c4374a..a6a409bc3 100644
--- a/src/packages/repositories.config
+++ b/src/packages/repositories.config
@@ -1,6 +1,7 @@
+