Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

iis

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();
like image 565
Darqer Avatar asked Apr 29 '12 11:04

Darqer


2 Answers

This might be what you are after:

var serverManager = new ServerManager();
serverManager.Sites["WebsiteName"].Applications["ApplicationName"].VirtualDirectories.Add("VirtualDirectoryName, "VirtualDirectoryPath");
like image 184
Steve Avatar answered Nov 10 '22 00:11

Steve


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.

like image 41
Ales Potocnik Hahonina Avatar answered Nov 10 '22 00:11

Ales Potocnik Hahonina