/// <summary> /// Get the webroot for the CDN site, initialized with a base web.config prepared for URL REWRITING /// </summary> /// <returns></returns> public string GetCdnWebConfigPathInitialized() { var basedir = UtilsSystem.EnsureDirectoryExists( UtilsSystem.CombinePaths(this.GlobalSettings.GetDefaultApplicationStorage().path, "__chef_cdn"), true); var webconfigfilepath = UtilsSystem.CombinePaths(basedir, "web.config"); // Si no hay un web.config plantilla, crearlo ahora. if (!File.Exists(webconfigfilepath)) { File.WriteAllText(webconfigfilepath, @" <configuration> <system.webServer> <rewrite> <rules> </rules> <outboundRules> </outboundRules> </rewrite> </system.webServer> </configuration> "); } UtilsWindowsAccounts.AddPermissionToDirectoryIfMissing(new SecurityIdentifier(UtilsWindowsAccounts.WELL_KNOWN_SID_USERS), basedir, FileSystemRights.ReadAndExecute); // Make sure that the site exists using (ServerManager manager = new ServerManager()) { bool configChanged = false; var site = UtilsIis.FindSiteWithName(manager, this.CstChefCndSiteName, this.Logger) .FirstOrDefault(); if (site == null) { manager.Sites.Add(this.CstChefCndSiteName, "http", $"{UtilsIis.LOCALHOST_ADDRESS}:80:{this.CstChefInternalHostname}", basedir); configChanged = true; } else { if (site.Applications.First().VirtualDirectories.First().PhysicalPath != basedir) { site.Applications.First().VirtualDirectories.First().PhysicalPath = basedir; configChanged = true; } } if (configChanged) { UtilsIis.CommitChanges(manager); } } this.UtilsHosts.AddHostsMapping(UtilsIis.LOCALHOST_ADDRESS, this.CstChefInternalHostname, "chf_IISDeployer_CDN"); // Add a cross domain file var crossdomainfilepath = UtilsSystem.CombinePaths(Path.GetDirectoryName(webconfigfilepath), "crossdomain.xml"); File.WriteAllText(crossdomainfilepath, UtilsSystem.GetEmbededResourceAsString(Assembly.GetExecutingAssembly(), "IIS.crossdomain.xml")); // Add common proxy headers UtilsIis.AddAllowedServerVariablesForUrlRewrite( this.CstChefCndSiteName, "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED_PROTO", "HTTP_X_FORWARDED_HOST"); return(webconfigfilepath); }