PC Review


Reply
Thread Tools Rate Thread

DirectoryServices.DirectoryEntry - Creating virtual directories in

 
 
=?Utf-8?B?cGF1bA==?=
Guest
Posts: n/a
 
      8th Aug 2005
I'm using the DirectoryServices class to try and create new virtual
directories in IIS.
Here's the code I'm using:

System.DirectoryServices.DirectoryEntry oDE;
System.DirectoryServices.DirectoryEntries oDC;
System.DirectoryServices.DirectoryEntry oVirDir;
string sIISPath = @"IIS:\\localhost\W3SVC\1\Root";
//Assuming it exists, we bind our DirectoryEntry object, oDE, to this root
using:
if (VirDirExists(sIISPath))
{
oDE = new System.DirectoryServices.DirectoryEntry(sIISPath);
//We obtain a collection of all of the children virtual directories under
this root object using:
oDC = oDE.Children;
//Add a new member to this collection and bind it to a new DirectoryEntry
object, oVirDir, thus creating a new
//virtual directory with:
oVirDir = oDC.Add(virDirName, oDE.SchemaClassName.ToString());
//Commit the changes to the IIS Metabase.
oVirDir.CommitChanges();
//Setting and Updating Any of the Properties on IIS
//We additionally need to assign a physical path to this new virtual
directory, using a straightforward
//property-setting approach:
oVirDir.Properties["Path"][0]= physicalPath;
oVirDir.Properties["DefaultDoc"][0] = "home_here.aspx";
oVirDir.Properties["AppFriendlyName"][0] = textBox1.Text.Trim();
oVirDir.Properties["CreateProcessAsUser"][0] = true;
oVirDir.CommitChanges();

This works fine in that it adds the entry to the default web site and set's
the appropriate properties. However, it does not 'create' the application.
You need to physically go into the virtual directory properties(in the IIS
snapin), go to the Virtual Directory tab, and click the <CREATE> button next
to the Application Name textbox in order to get the virtual directory to work
in IIS.

I can't seem to find an method that does this programatically in the
DirectoryServices class. Does any one knows what this would be or if there
is another way to create virtual directories programatically in IIS?

Thanks for your help

Paul
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmFrb2IgQ2hyaXN0ZW5zZW4=?=
Guest
Posts: n/a
 
      8th Aug 2005
Hey Paul,

You need to set the AppRoot property as well. This will cause the
application to be created. E.g.:

vdir.Properties["AppRoot"].Value = "/LM/W3SVC/1/Root/TESTSITE";

HTH, Jakob.
--
http://www.dotninjas.dk
http://www.powerbytes.dk


"paul" wrote:

> I'm using the DirectoryServices class to try and create new virtual
> directories in IIS.
> Here's the code I'm using:
>
> System.DirectoryServices.DirectoryEntry oDE;
> System.DirectoryServices.DirectoryEntries oDC;
> System.DirectoryServices.DirectoryEntry oVirDir;
> string sIISPath = @"IIS:\\localhost\W3SVC\1\Root";
> //Assuming it exists, we bind our DirectoryEntry object, oDE, to this root
> using:
> if (VirDirExists(sIISPath))
> {
> oDE = new System.DirectoryServices.DirectoryEntry(sIISPath);
> //We obtain a collection of all of the children virtual directories under
> this root object using:
> oDC = oDE.Children;
> //Add a new member to this collection and bind it to a new DirectoryEntry
> object, oVirDir, thus creating a new
> //virtual directory with:
> oVirDir = oDC.Add(virDirName, oDE.SchemaClassName.ToString());
> //Commit the changes to the IIS Metabase.
> oVirDir.CommitChanges();
> //Setting and Updating Any of the Properties on IIS
> //We additionally need to assign a physical path to this new virtual
> directory, using a straightforward
> //property-setting approach:
> oVirDir.Properties["Path"][0]= physicalPath;
> oVirDir.Properties["DefaultDoc"][0] = "home_here.aspx";
> oVirDir.Properties["AppFriendlyName"][0] = textBox1.Text.Trim();
> oVirDir.Properties["CreateProcessAsUser"][0] = true;
> oVirDir.CommitChanges();
>
> This works fine in that it adds the entry to the default web site and set's
> the appropriate properties. However, it does not 'create' the application.
> You need to physically go into the virtual directory properties(in the IIS
> snapin), go to the Virtual Directory tab, and click the <CREATE> button next
> to the Application Name textbox in order to get the virtual directory to work
> in IIS.
>
> I can't seem to find an method that does this programatically in the
> DirectoryServices class. Does any one knows what this would be or if there
> is another way to create virtual directories programatically in IIS?
>
> Thanks for your help
>
> Paul

 
Reply With Quote
 
=?Utf-8?B?cGF1bA==?=
Guest
Posts: n/a
 
      8th Aug 2005
That was it.
Thanks!

"Jakob Christensen" wrote:

> Hey Paul,
>
> You need to set the AppRoot property as well. This will cause the
> application to be created. E.g.:
>
> vdir.Properties["AppRoot"].Value = "/LM/W3SVC/1/Root/TESTSITE";
>
> HTH, Jakob.
> --
> http://www.dotninjas.dk
> http://www.powerbytes.dk
>
>
> "paul" wrote:
>
> > I'm using the DirectoryServices class to try and create new virtual
> > directories in IIS.
> > Here's the code I'm using:
> >
> > System.DirectoryServices.DirectoryEntry oDE;
> > System.DirectoryServices.DirectoryEntries oDC;
> > System.DirectoryServices.DirectoryEntry oVirDir;
> > string sIISPath = @"IIS:\\localhost\W3SVC\1\Root";
> > //Assuming it exists, we bind our DirectoryEntry object, oDE, to this root
> > using:
> > if (VirDirExists(sIISPath))
> > {
> > oDE = new System.DirectoryServices.DirectoryEntry(sIISPath);
> > //We obtain a collection of all of the children virtual directories under
> > this root object using:
> > oDC = oDE.Children;
> > //Add a new member to this collection and bind it to a new DirectoryEntry
> > object, oVirDir, thus creating a new
> > //virtual directory with:
> > oVirDir = oDC.Add(virDirName, oDE.SchemaClassName.ToString());
> > //Commit the changes to the IIS Metabase.
> > oVirDir.CommitChanges();
> > //Setting and Updating Any of the Properties on IIS
> > //We additionally need to assign a physical path to this new virtual
> > directory, using a straightforward
> > //property-setting approach:
> > oVirDir.Properties["Path"][0]= physicalPath;
> > oVirDir.Properties["DefaultDoc"][0] = "home_here.aspx";
> > oVirDir.Properties["AppFriendlyName"][0] = textBox1.Text.Trim();
> > oVirDir.Properties["CreateProcessAsUser"][0] = true;
> > oVirDir.CommitChanges();
> >
> > This works fine in that it adds the entry to the default web site and set's
> > the appropriate properties. However, it does not 'create' the application.
> > You need to physically go into the virtual directory properties(in the IIS
> > snapin), go to the Virtual Directory tab, and click the <CREATE> button next
> > to the Application Name textbox in order to get the virtual directory to work
> > in IIS.
> >
> > I can't seem to find an method that does this programatically in the
> > DirectoryServices class. Does any one knows what this would be or if there
> > is another way to create virtual directories programatically in IIS?
> >
> > Thanks for your help
> >
> > Paul

 
Reply With Quote
 
Guest
Posts: n/a
 
      9th Aug 2005
"paul" <(E-Mail Removed)> wrote in message
news:1225947B-FB78-4C7D-941A-(E-Mail Removed)...

> I can't seem to find an method that does this programatically in the
> DirectoryServices class. Does any one knows what this would be or if
> there
> is another way to create virtual directories programatically in IIS?


Paul,

You should invoke the method AppCreate, AppCreate2 or AppCreate3 on the
IIsWebDirectory directory entry object, eg:

public void CreateApplication(string path, string name, string
applicationPool, IIsInProcessFlags flag)
{
if (path == null)
throw new ArgumentNullExpcetion("path");

if (name == null)
throw new ArgumentNullException("name");

using (DirectoryEntry entry = new DirectoryEntry(path))
{
entry.Invoke("AppCreate2", new object[1] { (int)flag });
entry.Properties["AppFriendlyName"].Value = name;
if (applicationPool != null)
entry.Properties["AppPoolId"].Value = applicationPool;
entry.CommitChanges();
}
}


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Authentication questions regarding System.DirectoryServices.DirectoryEntry(...) Chris Newby Microsoft Dot NET Framework 0 16th May 2006 05:50 PM
system.directoryservices - directoryentry.children Joe User Microsoft Dot NET Framework 5 4th May 2005 07:04 AM
creating Virtual directories on the fly Stimp Microsoft ASP .NET 2 23rd Aug 2004 01:56 PM
Creating Virtual Directories at my ISP gemel Microsoft ASP .NET 1 10th Jun 2004 01:53 PM
Bug In DirectoryServices DirectoryEntry? Bill Ingalls Microsoft Dot NET Framework 3 16th Oct 2003 09:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:20 PM.