Reputation:
I would like to know if it possible to create a virtual directory in C# directly to a site instead of creating a web application and then linking a virtual directory to that. I am using iis 7. thanks ! Src:http://blogs.msdn.com/b/carlosag/archive/2006/04/17/microsoftwebadministration.aspx
Upvotes: 1
Views: 2633
Reputation: 1352
Using Microsoft.Web.Administration you can do:
ServerManager iisManager = new ServerManager();
Application app = iisManager.Sites[“NewSite”].Applications[“/Sales”];
app.VirtualDirectories.Add(“/VDir”, “d:\\MyVDir”);
iisManager.CommitChanges();
Read more on it here:
Upvotes: 0
Reputation: 1064
you can do this in c#. worked for me.
using (ServerManager srv = new ServerManager())
{
var site = srv.Sites.FirstOrDefault(c => c.Name == siteName);
var app = site.Applications.Add("/SubDirecory1/SubDirectory2", acbphysicalPath.Text + @"\SubDirectory1\SubDirectory2");
app.ApplicationPoolName = txtAppPool.Text;
srv.CommitChanges();
}
Upvotes: 0
Reputation: 214
You can do this in PowerShell.
PS IIS:\> New-Item 'IIS:\Sites\Default Web Site\DemoVirtualDir1' -type VirtualDirectory -physicalPath c:\test\virtualDirectory1
Upvotes: 1