简体   繁体   中英

How to correctly link the installed web application name and its virtual directory name?

Using ServerManager, I can get the list of virtual directories for my installed web applications. I can also verify if a specific web application is installed using registry key search. I am, however, unable to locate the web application physical path that is usually in inetpub\\wwwroot.

InstallLocation field in the related registry does not have any value. How can I achieve this?

You can use DirectoryEntry to browse the IIS configuration. Here is an example pulled from another question :

void ListVirtualDirectories(string serverName, int siteId) {            
   DirectoryEntry iisServer = new DirectoryEntry("IIS://" + serverName + "/W3SVC/" + siteId + "/ROOT");

   foreach (DirectoryEntry webDir in iisServer.Children) {
       if (webDir.SchemaClassName.Equals("IIsWebVirtualDir"))
               Console.WriteLine("Found virtual directory {0}", webDir.Name);
   }
}

The siteId is a numerical value corresponding to each site listed in IIS. This method forces you to provide it, but you could find all the sites on the server too if you wanted. Just search Google for that if you need it. But this should get you started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM