From 181998b145452264677db16a7907ac65ae200622 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 6 Mar 2013 12:53:22 +0200 Subject: [PATCH] IIS7. Enable/Disable Compression --- .../Web/WebVirtualDirectory.cs | 13 +++++ .../Compression/CompressionModuleService.cs | 53 +++++++++++++++++++ .../WebsitePanel.Providers.Web.IIS70/IIs70.cs | 17 +++++- .../WebsitePanel.Providers.Web.IIs70.csproj | 1 + .../WebSitesHomeFolderControl.ascx.resx | 9 ++++ .../WebSitesHomeFolderControl.ascx | 20 ++++++- .../WebSitesHomeFolderControl.ascx.cs | 5 ++ ...WebSitesHomeFolderControl.ascx.designer.cs | 36 ++++++++++--- 8 files changed, 144 insertions(+), 10 deletions(-) create mode 100644 WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Compression/CompressionModuleService.cs diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Web/WebVirtualDirectory.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Web/WebVirtualDirectory.cs index 3be281fd..e89c2250 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Web/WebVirtualDirectory.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Web/WebVirtualDirectory.cs @@ -56,6 +56,8 @@ namespace WebsitePanel.Providers.Web private bool enableAnonymousAccess; private bool enableWindowsAuthentication; private bool enableBasicAuthentication; + private bool enableDynamicCompression; + private bool enableStaticCompression; private string defaultDocs; private string httpRedirect; private HttpError[] httpErrors; @@ -167,6 +169,17 @@ namespace WebsitePanel.Providers.Web set { this.enableBasicAuthentication = value; } } + public bool EnableDynamicCompression + { + get { return this.enableDynamicCompression; } + set { this.enableDynamicCompression = value; } + } + public bool EnableStaticCompression + { + get { return this.enableStaticCompression; } + set { this.enableStaticCompression = value; } + } + public bool AspInstalled { get { return this.aspInstalled; } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Compression/CompressionModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Compression/CompressionModuleService.cs new file mode 100644 index 00000000..8602675e --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Compression/CompressionModuleService.cs @@ -0,0 +1,53 @@ +using System; +using Microsoft.Web.Administration; +using Microsoft.Web.Management.Server; +using WebsitePanel.Providers.Web.Iis.Common; + +namespace WebsitePanel.Providers.Web.Compression +{ + + internal static class CompressionGlobals + { + public const int DynamicCompression = 1; + public const int StaticCompression = 2; + } + + + internal sealed class CompressionModuleService : ConfigurationModuleService + { + public const string DynamicCompression = "doDynamicCompression"; + public const string StaticCompression = "doStaticCompression"; + + public PropertyBag GetSettings(ServerManager srvman, string siteId) + { + var config = srvman.GetApplicationHostConfiguration(); + // + var section = config.GetSection(Constants.CompressionSection, siteId); + // + PropertyBag bag = new PropertyBag(); + // + bag[CompressionGlobals.DynamicCompression] = Convert.ToBoolean(section.GetAttributeValue(DynamicCompression)); + bag[CompressionGlobals.StaticCompression] = Convert.ToBoolean(section.GetAttributeValue(StaticCompression)); + // + return bag; + } + + public void SetSettings(string virtualPath, bool doDynamicCompression, bool doStaticCompression) + { + using (var srvman = GetServerManager()) + { + var config = srvman.GetApplicationHostConfiguration(); + // + var section = config.GetSection(Constants.CompressionSection, virtualPath); + // + section.SetAttributeValue(DynamicCompression, doDynamicCompression); + section.SetAttributeValue(StaticCompression, doStaticCompression); + + // + srvman.CommitChanges(); + } + } + + + } +} diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/IIs70.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/IIs70.cs index 4621a078..0b436282 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/IIs70.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/IIs70.cs @@ -38,6 +38,7 @@ using WebsitePanel.Providers.HostedSolution; using WebsitePanel.Providers.OS; using WebsitePanel.Providers.ResultObjects; using WebsitePanel.Providers.Utils; +using WebsitePanel.Providers.Web.Compression; using WebsitePanel.Providers.Web.Handlers; using WebsitePanel.Providers.Web.HttpRedirect; using WebsitePanel.Providers.Web.Iis.Authentication; @@ -78,6 +79,7 @@ namespace WebsitePanel.Providers.Web public const string AnonymousAuthenticationSection = "system.webServer/security/authentication/anonymousAuthentication"; public const string BasicAuthenticationSection = "system.webServer/security/authentication/basicAuthentication"; public const string WindowsAuthenticationSection = "system.webServer/security/authentication/windowsAuthentication"; + public const string CompressionSection = "system.webServer/urlCompression"; public const string StaticContentSection = "system.webServer/staticContent"; public const string ModulesSection = "system.webServer/modules"; public const string IsapiCgiRestrictionSection = "system.webServer/security/isapiCgiRestriction"; @@ -347,6 +349,7 @@ namespace WebsitePanel.Providers.Web private AnonymAuthModuleService anonymAuthSvc; private WindowsAuthModuleService winAuthSvc; private BasicAuthModuleService basicAuthSvc; + private CompressionModuleService comprSvc; private DefaultDocsModuleService defaultDocSvc; private CustomHttpErrorsModuleService customErrorsSvc; private CustomHttpHeadersModuleService customHeadersSvc; @@ -519,6 +522,7 @@ namespace WebsitePanel.Providers.Web winAuthSvc = new WindowsAuthModuleService(); anonymAuthSvc = new AnonymAuthModuleService(); basicAuthSvc = new BasicAuthModuleService(); + comprSvc = new CompressionModuleService(); defaultDocSvc = new DefaultDocsModuleService(); classicAspSvc = new ClassicAspModuleService(); httpRedirectSvc = new HttpRedirectModuleService(); @@ -623,6 +627,8 @@ namespace WebsitePanel.Providers.Web virtualDir.AnonymousUserPassword = (string)bag[AuthenticationGlobals.AnonymousAuthenticationPassword]; virtualDir.EnableAnonymousAccess = (bool)bag[AuthenticationGlobals.Enabled]; + + // load windows auth bag = winAuthSvc.GetAuthenticationSettings(srvman, virtualDir.FullQualifiedPath); virtualDir.EnableWindowsAuthentication = (bool)bag[AuthenticationGlobals.Enabled]; @@ -636,10 +642,17 @@ namespace WebsitePanel.Providers.Web bag = classicAspSvc.GetClassicAspSettings(srvman, virtualDir.FullQualifiedPath); virtualDir.EnableParentPaths = (bool)bag[ClassicAspGlobals.EnableParentPaths]; // + + //gzip + bag = comprSvc.GetSettings(srvman, virtualDir.FullQualifiedPath); + virtualDir.EnableDynamicCompression = (bool)bag[CompressionGlobals.DynamicCompression]; + virtualDir.EnableStaticCompression = (bool)bag[CompressionGlobals.StaticCompression]; + virtualDir.IIs7 = true; } - private void FillIISObjectFromVirtualDirectory(WebVirtualDirectory virtualDir) + + private void FillIISObjectFromVirtualDirectory(WebVirtualDirectory virtualDir) { dirBrowseSvc.SetDirectoryBrowseEnabled(virtualDir.FullQualifiedPath, virtualDir.EnableDirectoryBrowsing); // @@ -648,6 +661,8 @@ namespace WebsitePanel.Providers.Web winAuthSvc.SetEnabled(virtualDir.FullQualifiedPath, virtualDir.EnableWindowsAuthentication); // basicAuthSvc.SetAuthenticationSettings(virtualDir); + // + comprSvc.SetSettings(virtualDir.FullQualifiedPath, virtualDir.EnableDynamicCompression, virtualDir.EnableStaticCompression); // defaultDocSvc.SetDefaultDocumentSettings(virtualDir.FullQualifiedPath, virtualDir.DefaultDocs); // diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebsitePanel.Providers.Web.IIs70.csproj b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebsitePanel.Providers.Web.IIs70.csproj index eee780ba..7fda4ba2 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebsitePanel.Providers.Web.IIs70.csproj +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebsitePanel.Providers.Web.IIs70.csproj @@ -91,6 +91,7 @@ + diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/App_LocalResources/WebSitesHomeFolderControl.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/App_LocalResources/WebSitesHomeFolderControl.ascx.resx index 9f46d8bc..9413de4d 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/App_LocalResources/WebSitesHomeFolderControl.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/App_LocalResources/WebSitesHomeFolderControl.ascx.resx @@ -129,6 +129,12 @@ Enable Basic Authentication + + Enable Dynamic Compression + + + Enable Static Compression + Enable Integrated Windows Authentication @@ -159,6 +165,9 @@ Authentication: + + Compression: + Default Documents: diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebSitesHomeFolderControl.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebSitesHomeFolderControl.ascx index c2aaadfd..bc901259 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebSitesHomeFolderControl.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebSitesHomeFolderControl.ascx @@ -52,6 +52,7 @@ +
@@ -69,8 +70,25 @@ -
+ +
+ + + + + + + + + + + + +
+ +
+ diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebSitesHomeFolderControl.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebSitesHomeFolderControl.ascx.cs index 1eaf38bb..e4187bbb 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebSitesHomeFolderControl.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebSitesHomeFolderControl.ascx.cs @@ -81,6 +81,8 @@ namespace WebsitePanel.Portal chkAuthAnonymous.Checked = item.EnableAnonymousAccess; chkAuthWindows.Checked = item.EnableWindowsAuthentication; chkAuthBasic.Checked = item.EnableBasicAuthentication; + chkDynamicCompression.Checked = item.EnableDynamicCompression; + chkStaticCompression.Checked = item.EnableStaticCompression; // default documents txtDefaultDocs.Text = String.Join("\n", item.DefaultDocs.Split(',', ';')); @@ -131,6 +133,9 @@ namespace WebsitePanel.Portal item.EnableAnonymousAccess = chkAuthAnonymous.Checked; item.EnableWindowsAuthentication = chkAuthWindows.Checked; item.EnableBasicAuthentication = chkAuthBasic.Checked; + item.EnableDynamicCompression = chkDynamicCompression.Checked; + item.EnableStaticCompression = chkStaticCompression.Checked; + // default documents item.DefaultDocs = String.Join(",", Utils.ParseDelimitedString(txtDefaultDocs.Text, '\n', '\r', ';', ',')); diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebSitesHomeFolderControl.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebSitesHomeFolderControl.ascx.designer.cs index 2fb3b311..86984cc6 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebSitesHomeFolderControl.ascx.designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebSitesHomeFolderControl.ascx.designer.cs @@ -1,22 +1,15 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.312 // // Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// the code is regenerated. // //------------------------------------------------------------------------------ namespace WebsitePanel.Portal { - /// - /// WebSitesHomeFolderControl class. - /// - /// - /// Auto-generated class. - /// public partial class WebSitesHomeFolderControl { /// @@ -163,6 +156,33 @@ namespace WebsitePanel.Portal { /// protected global::System.Web.UI.WebControls.CheckBox chkAuthBasic; + /// + /// lblCompression control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label lblCompression; + + /// + /// chkDynamicCompression control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.CheckBox chkDynamicCompression; + + /// + /// chkStaticCompression control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.CheckBox chkStaticCompression; + /// /// pnlDefaultDocuments control. ///