/// <summary> /// Adds a virtual directory to a IIS site /// </summary> /// <param name="settings">The settings of the virtual directory to add</param> /// <returns>If the virtual directory was added.</returns> public bool AddVirtualDirectory(VirtualDirectorySettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } if (string.IsNullOrWhiteSpace(settings.Path)) { throw new ArgumentException("Site name cannot be null!"); } if (string.IsNullOrWhiteSpace(settings.ApplicationPath)) { throw new ArgumentException("Applicaiton path cannot be null!"); } //Get Site Site site = _Server.Sites.SingleOrDefault(p => p.Name == settings.SiteName); if (site == null) { throw new Exception("Site '" + settings.SiteName + "' does not exist."); } //Get Application Application app = site.Applications.SingleOrDefault(p => p.Path == settings.ApplicationPath); if (app == null) { throw new Exception("Application '" + settings.ApplicationPath + "' does not exist."); } if (app.VirtualDirectories.Any(vd => vd.Path == settings.Path)) { throw new Exception("Virtual Directory '" + settings.Path + "' already exists."); } //Get Directory VirtualDirectory vDir = app.VirtualDirectories.CreateElement(); vDir.Path = settings.Path; vDir.PhysicalPath = this.GetPhysicalDirectory(settings); app.VirtualDirectories.Add(vDir); //this.SetAuthentication("webServer", settings.SiteName, settings.ApplicationPath, settings.Authentication); //this.SetAuthorization("webServer", settings.SiteName, settings.ApplicationPath, settings.Authorization); _Server.CommitChanges(); return(true); }
/// <summary> /// Removes a virtual directory from a IIS site /// </summary> /// <param name="settings">The settings of the virtual directory to remove</param> /// <returns>If the virtual directory was removed.</returns> public bool RemoveVirtualDirectory(VirtualDirectorySettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } if (string.IsNullOrWhiteSpace(settings.SiteName)) { throw new ArgumentException("Site name cannot be null!"); } if (string.IsNullOrWhiteSpace(settings.ApplicationPath)) { throw new ArgumentException("Applicaiton path cannot be null!"); } //Get Site Site site = _Server.Sites.SingleOrDefault(p => p.Name == settings.SiteName); if (site != null) { //Get Application Application app = site.Applications.SingleOrDefault(p => p.Path == settings.ApplicationPath); if (app == null) { throw new Exception("Application '" + settings.ApplicationPath + "' does not exist."); } else { VirtualDirectory vd = app.VirtualDirectories.FirstOrDefault(p => p.Path == settings.Path); if (vd == null) { throw new Exception("Virtual directory '" + settings.Path + "' does not exist."); } else { app.VirtualDirectories.Remove(vd); _Server.CommitChanges(); return(true); } } } else { throw new Exception("Site '" + settings.SiteName + "' does not exist."); } }
public static bool SiteVirtualDirectoryExists(this ICakeContext context, string server, VirtualDirectorySettings settings) { using (ServerManager manager = BaseManager.Connect(server)) { return(WebsiteManager .Using(context.Environment, context.Log, manager) .VirtualDirectoryExists(settings)); } }
public static void RemoveSiteVirtualDirectory(this ICakeContext context, string server, VirtualDirectorySettings settings) { using (ServerManager manager = BaseManager.Connect(server)) { WebsiteManager .Using(context.Environment, context.Log, manager) .RemoveVirtualDirectory(settings); } }
public static void RemoveSiteVirtualDirectory(this ICakeContext context, VirtualDirectorySettings settings) { context.RemoveSiteVirtualDirectory("", settings); }
public static void AddSiteVirtualDirectory(this ICakeContext context, string server, VirtualDirectorySettings settings) { using (ServerManager manager = BaseManager.Connect(server)) { settings.ComputerName = server; WebsiteManager .Using(context.Environment, context.Log, manager) .AddVirtualDirectory(settings); } }
public static bool SiteVirtualDirectoryExists(this ICakeContext context, VirtualDirectorySettings settings) { return(context.SiteVirtualDirectoryExists("", settings)); }