/// <summary> /// Enables Helicon Ape module & handler on the web site or server globally. /// </summary> /// <param name="siteId"> /// Web site id or empty string ("") for server-wide enabling /// </param> public override void EnableHeliconApe(string siteId) { if (null == siteId) { throw new ArgumentNullException("siteId"); } if ("" != siteId) { // prepare enabling Ape for web site WebSite webSite = null; using (ServerManager srvman = webObjectsSvc.GetServerManager()) { // Helicon.Ape.ApeModule works for apps working in Integrated Pipeline mode // Switch automatically to the app pool with Integrated Pipeline enabled webSite = webObjectsSvc.GetWebSiteFromIIS(srvman, siteId); if (webSite == null) throw new ApplicationException( String.Format("Could not find a web site with the following identifier: {0}.", siteId)); // Fill ASP.NET settings FillAspNetSettingsFromIISObject(srvman, webSite); } // var aphl = new WebAppPoolHelper(ProviderSettings); var currentPool = aphl.match_webapp_pool(webSite); var dotNetVersion = aphl.dotNetVersion(currentPool.Mode); var sisMode = aphl.isolation(currentPool.Mode); // AT least ASP.NET 2.0 is allowed to provide such capabilities... if (dotNetVersion == SiteAppPoolMode.dotNetFramework1) dotNetVersion = SiteAppPoolMode.dotNetFramework2; // and Integrated pipeline... if (aphl.pipeline(currentPool.Mode) != SiteAppPoolMode.Integrated) { // Lookup for the opposite pool matching the criteria var oppositePool = Array.Find<WebAppPool>(aphl.SupportedAppPools.ToArray(), x => aphl.dotNetVersion(x.Mode) == dotNetVersion && aphl.isolation(x.Mode) == sisMode && aphl.pipeline(x.Mode) == SiteAppPoolMode.Integrated); // webSite.AspNetInstalled = oppositePool.AspNetInstalled; // SetWebSiteApplicationPool(webSite, false); // using (var srvman = webObjectsSvc.GetServerManager()) { var iisSiteObject = srvman.Sites[siteId]; iisSiteObject.Applications["/"].ApplicationPoolName = webSite.ApplicationPool; // srvman.CommitChanges(); } } #region Disable automatically Integrated Windows Authentication using (var srvman = webObjectsSvc.GetServerManager()) { PropertyBag winAuthBag = winAuthSvc.GetAuthenticationSettings(srvman, siteId); // if ((bool) winAuthBag[AuthenticationGlobals.Enabled]) { Configuration config = srvman.GetApplicationHostConfiguration(); ConfigurationSection windowsAuthenticationSection = config.GetSection( "system.webServer/security/authentication/windowsAuthentication", siteId); // windowsAuthenticationSection["enabled"] = false; // srvman.CommitChanges(); } } #endregion #region Disable automatically Secured Folders if (IsSecuredFoldersInstalled(siteId)) { UninstallSecuredFolders(siteId); } #endregion } using (var srvman = webObjectsSvc.GetServerManager()) { if (!IsHeliconApeEnabled(srvman, siteId)) { Configuration appConfig = srvman.GetApplicationHostConfiguration(); // add Helicon.Ape module ConfigurationSection modulesSection = appConfig.GetSection(Constants.ModulesSection, siteId); ConfigurationElementCollection modulesCollection = modulesSection.GetCollection(); // <add name="Helicon.Ape" /> ConfigurationElement heliconApeModuleEntry = modulesCollection.CreateElement("add"); heliconApeModuleEntry["name"] = Constants.HeliconApeModule; heliconApeModuleEntry["type"] = GetHeliconApeModuleType(siteId); // this way make <clear/> and copy all modules list from ancestor //modulesCollection.AddAt(0, heliconApeModuleEntry); // this way just insert single ape module entry modulesCollection.Add(heliconApeModuleEntry); // add Helicon.Ape handler ConfigurationSection handlersSection = appConfig.GetSection(Constants.HandlersSection, siteId); ConfigurationElementCollection handlersCollection = handlersSection.GetCollection(); // <add name="Helicon.Ape" /> ConfigurationElement heliconApeHandlerEntry = handlersCollection.CreateElement("add"); heliconApeHandlerEntry["name"] = Constants.HeliconApeHandler; heliconApeHandlerEntry["type"] = GetHeliconApeHandlerType(siteId); heliconApeHandlerEntry["path"] = Constants.HeliconApeHandlerPath; heliconApeHandlerEntry["verb"] = "*"; heliconApeHandlerEntry["resourceType"] = "Unspecified"; handlersCollection.AddAt(0, heliconApeHandlerEntry); srvman.CommitChanges(); } } }
/// <summary> /// /// </summary> /// <exception cref="System.ArgumentNullException" /> /// <exception cref="System.ApplicationException" /> /// <param name="siteId"></param> public override void InstallSecuredFolders(string siteId) { // if (String.IsNullOrEmpty(siteId)) throw new ArgumentNullException("siteId"); // WebsitePanel.IIsModules works for apps working in Integrated Pipeline mode #region Switch automatically to the app pool with Integrated Pipeline enabled var webSite = webObjectsSvc.GetWebSiteFromIIS(siteId); // if (webSite == null) throw new ApplicationException(String.Format("Could not find a web site with the following identifier: {0}.", siteId)); // var aphl = new WebAppPoolHelper(ProviderSettings); // Fill ASP.NET settings FillAspNetSettingsFromIISObject(webSite); // var currentPool = aphl.match_webapp_pool(webSite); var dotNetVersion = aphl.dotNetVersion(currentPool.Mode); var sisMode = aphl.isolation(currentPool.Mode); // AT least ASP.NET 2.0 is allowed to provide such capabilities... if (dotNetVersion == SiteAppPoolMode.dotNetFramework1) dotNetVersion = SiteAppPoolMode.dotNetFramework2; // and Integrated pipeline... if (aphl.pipeline(currentPool.Mode) != SiteAppPoolMode.Integrated) { // Lookup for the opposite pool matching the criteria var oppositePool = Array.Find<WebAppPool>(aphl.SupportedAppPools.ToArray(), x => aphl.dotNetVersion(x.Mode) == dotNetVersion && aphl.isolation(x.Mode) == sisMode && aphl.pipeline(x.Mode) == SiteAppPoolMode.Integrated); // webSite.AspNetInstalled = oppositePool.AspNetInstalled; // SetWebSiteApplicationPool(webSite, false); // using (var srvman = webObjectsSvc.GetServerManager()) { var iisSiteObject = srvman.Sites[siteId]; iisSiteObject.Applications["/"].ApplicationPoolName = webSite.ApplicationPool; // srvman.CommitChanges(); } } #endregion #region Disable automatically Integrated Windows Authentication PropertyBag winAuthBag = winAuthSvc.GetAuthenticationSettings(siteId); // if ((bool)winAuthBag[AuthenticationGlobals.Enabled]) { // using (var srvman = webObjectsSvc.GetServerManager()) { Configuration config = srvman.GetApplicationHostConfiguration(); ConfigurationSection windowsAuthenticationSection = config.GetSection( "system.webServer/security/authentication/windowsAuthentication", siteId); // windowsAuthenticationSection["enabled"] = false; // srvman.CommitChanges(); } } #endregion // using (var srvman = webObjectsSvc.GetServerManager()) { // Configuration appConfig = srvman.GetApplicationHostConfiguration(); // ConfigurationSection modulesSection = appConfig.GetSection(Constants.ModulesSection, siteId); // ConfigurationElementCollection modulesCollection = modulesSection.GetCollection(); // ConfigurationElement moduleAdd = modulesCollection.CreateElement("add"); // moduleAdd["name"] = Constants.WEBSITEPANEL_IISMODULES; moduleAdd["type"] = SecureFoldersModuleAssembly; moduleAdd["preCondition"] = "managedHandler"; // modulesCollection.Add(moduleAdd); // srvman.CommitChanges(); } }
private bool IsHeliconApeEnabled(ServerManager srvman, string siteId) { if (!string.IsNullOrEmpty(siteId)) { // Check the web site app pool in integrated pipeline mode WebSite webSite = null; webSite = webObjectsSvc.GetWebSiteFromIIS(srvman, siteId); if (webSite == null) throw new ApplicationException( String.Format("Could not find a web site with the following identifier: {0}.", siteId)); // Fill ASP.NET settings FillAspNetSettingsFromIISObject(srvman, webSite); var aphl = new WebAppPoolHelper(ProviderSettings); var currentPool = aphl.match_webapp_pool(webSite); if (aphl.pipeline(currentPool.Mode) != SiteAppPoolMode.Integrated) { // Ape is not working in not Integrated pipeline mode return false; } } var appConfig = srvman.GetApplicationHostConfiguration(); var modulesSection = appConfig.GetSection(Constants.ModulesSection, siteId); var modulesCollection = modulesSection.GetCollection(); foreach (var moduleEntry in modulesCollection) { if ( String.Equals(moduleEntry["name"].ToString(), Constants.HeliconApeModule, StringComparison.InvariantCultureIgnoreCase) || String.Equals(moduleEntry["name"].ToString(), Constants.HeliconApeModulePrevName, StringComparison.InvariantCultureIgnoreCase) ) return true; } // return false; }