0 Comments

       /// <summary>
       /// Does the given IIS website contain virtualdirectories.
       /// </summary>
       /// <returns></returns>
       public bool DoesWebsiteContainVirtualDirectories(string website)
       {
           if (string.IsNullOrEmpty(website)) { throw new Exception("Parameter [website] can't be null or empty"); }
           bool result = false;

           DirectoryEntry w3svc = new DirectoryEntry("IIS://localhost/w3svc");

           foreach (DirectoryEntry site in w3svc.Children)
           {
               if (site.Properties["ServerComment"] != null)
               {
                   if (site.Properties["ServerComment"].Value != null)
                   {
                       if (site.SchemaClassName.Equals("IIsWebServer") && site.Properties["ServerComment"].Value.ToString().Equals(website))
                       {
                           foreach (DirectoryEntry child in site.Children)
                           {
                               if (!result)
                               {
                                   foreach (PropertyValueCollection property in child.Properties)
                                   {
                                       if (property.Value != null)
                                       {
                                           if (property.PropertyName.Equals("KeyType") && property.Value.ToString().Equals("IIsWebVirtualDir"))
                                           {
                                               return true;
                                           }
                                       }
                                   }
                               }
                           }
                       }
                   }
               }
           }

           return result;
       }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts