I'm searching for a way to create virtual directory with Microsoft.Web.Administration in a Default Web Site but without creating application.
The only way I found, creates 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();
This might be what you are after:
var serverManager = new ServerManager();
serverManager.Sites["WebsiteName"].Applications["ApplicationName"].VirtualDirectories.Add("VirtualDirectoryName, "VirtualDirectoryPath");
Not sure if this is still relevant but it's fairly hard to find any answers by searching alone. As I'm just struggling with answer to this exact question, the best I came up with is that in order to access virtual directories of a Microsoft.Web.Administration.Site you access the first application on it:
var serverManager = new ServerManager();
site = serverManager.Sites.Add(websiteName, physicalPath, port);
var dirs = site.Applications[0].VirtualDirectories;
A bit counter-intuitive but it seems like IIS will create a default application for a web site that you add.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With