IIS: Creating a Virtual Directory on a Website Using Microsoft.Web.Administration

I am looking for a way to create a virtual directory with Microsoft.Web.Administration on a default website, but without creating an application.

The only way I found creates an application:

Microsoft.Web.Administration.ServerManager manager = new Microsoft.Web.Administration.ServerManager(); Site defaultSite = manager.Sites[ "Default Web Site]; Microsoft.Web.Administration.Application app = defaultSite.Applications.Add( "\virtDir", "c:\\path" ); manager.CommitChanges(); 
+7
source share
2 answers

This might be what you need:

 var serverManager = new ServerManager(); serverManager.Sites["WebsiteName"].Applications["ApplicationName"].VirtualDirectories.Add("VirtualDirectoryName, "VirtualDirectoryPath"); 
+8
source

Not sure if this is still relevant, but it’s rather difficult to find the answers to them yourself. Since I'm just struggling with the answer to this exact question, the best I came up with is that to access the Microsoft.Web.Administration.Site virtual directories, you get access to the first application:

 var serverManager = new ServerManager(); site = serverManager.Sites.Add(websiteName, physicalPath, port); var dirs = site.Applications[0].VirtualDirectories; 

bit intuitive, but it looks like IIS will create a default application for the website you are adding.

+7
source

All Articles