简体   繁体   中英

IIS: How to create virtualdirectory in website with Microsoft.Web.Administration

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.

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