IIS And DirectoryServices

R

Ram

Hey,
How can I bind a DirectoryEntry to a IIsWebDirectory?
I tried the following code:
DirectoryEntry entry = new
DirectoryEntry("IIS://localhost/w3svc/1/root/webdirectory");
But the schematype of this entry is - IISObject and because of that - I cant
use the IIsWebDirectory's methods i.e - AppCreate.
Is there a way to tell the directoryentry what type of object this entry
represents?
Thanks ahead

--Ram
 
W

Willy Denoyette [MVP]

Where did you get this from, IISObject is a WMI type ?

Please post your whole code.

Willy.
 
R

Ram

Here's my code:
DirectoryEntry webEntry;
webEntry = new DirectoryEntry("IIS://localhost/w3svc/1/ROOT/newWebDir");
//Now, if I look in the locals window, the webEntry's SchemaClassName is -
"IISObject" where it should be IIsWebDirectory
webEntry.Invok("AppCreate",new object[]{true}); //This line gives me the
error since the entry is not of type - IIsWebDirectory...
webEntry.CommitChanges();
Thanks again,

--Ram
 
W

Willy Denoyette [MVP]

Ram said:
Here's my code:
DirectoryEntry webEntry;
webEntry = new DirectoryEntry("IIS://localhost/w3svc/1/ROOT/newWebDir");
//Now, if I look in the locals window, the webEntry's SchemaClassName is -
"IISObject" where it should be IIsWebDirectory
webEntry.Invok("AppCreate",new object[]{true}); //This line gives me
the
error since the entry is not of type - IIsWebDirectory...
webEntry.CommitChanges();
Thanks again,
Suspposed your "newWebDir" physical directory exists in your root path.
You must add the directory to the metabase as a IISWibDirectory using :

rootEntry.Children.Add("newWebDir","IIsWebDirectory");

Here is a complete sample that illustrates the creation of a WebDirectory
and an application associated with this one.

// Some required const definitions
// Authorization flags
const int MD_AUTH_ANONYMOUS = 0x00000001; //Anonymous authentication
available.
const int MD_AUTH_BASIC = 0x00000002; //Basic authentication available.
const int MD_AUTH_NT = 0x00000004; //Windows authentication schemes
available.
// Browse flags
const int MD_DIRBROW_SHOW_DATE = 0x00000002; //Show date.
const int MD_DIRBROW_SHOW_TIME = 0x00000004; // Show time.
const int MD_DIRBROW_SHOW_SIZE = 0x00000008; //Show file size.
const int MD_DIRBROW_SHOW_EXTENSION = 0x00000010; //Show file name
extension.
const int MD_DIRBROW_LONG_DATE = 0x00000020; //Show full date.
const int MD_DIRBROW_LOADDEFAULT = 0x40000000; // Load default page, if it
exists.
const uint MD_DIRBROW_ENABLED = 0x80000000;
// Access Flags
const int MD_ACCESS_READ = 0x00000001; //Allow read access.
const int MD_ACCESS_WRITE = 0x00000002; //Allow write access.
const int MD_ACCESS_EXECUTE = 0x00000004; //Allow file execution
(includes script permission).
const int MD_ACCESS_SOURCE = 0x00000010; //Allow source access.
const int MD_ACCESS_SCRIPT = 0x00000200; // Allow script execution.
const int MD_ACCESS_NO_REMOTE_WRITE = 0x00000400; // Local write access
only.
const int MD_ACCESS_NO_REMOTE_READ = 0x00001000; // Local read access
only.
const int MD_ACCESS_NO_REMOTE_EXECUTE = 0x00002000; // Local execution
only.

....

DirectoryEntry folderRoot = new
DirectoryEntry(("IIS://localhost/w3svc/1/ROOT", "administrator", "adminpwd",
AuthenticationTypes.Secure);
folderRoot.RefreshCache();
// Add the WebDirectory to the metabase
DirectoryEntry dir =
folderRoot.Children.Add("newWebDir","IIsWebDirectory");
dir.CommitChanges();

// Set some Properties
dir.Properties["AuthFlags"].Value = MD_AUTH_ANONYMOUS |
MD_AUTH_NT;
dir.Properties["DefaultDoc"].Value = "default.aspx";
dir.Properties["DirBrowseFlags"].Value = MD_DIRBROW_SHOW_DATE |
MD_DIRBROW_ENABLED |
MD_DIRBROW_SHOW_SIZE | MD_DIRBROW_SHOW_EXTENSION |
MD_DIRBROW_LONG_DATE | MD_DIRBROW_LOADDEFAULT;
dir.Properties["AccessFlags"].Value = MD_ACCESS_READ |
MD_ACCESS_SCRIPT;

// Call AppCreat2 to create a Web application (0 =In-proc, 1 =
Out-proc, 2 = Pooled) , not needed for ASP.NET
object[] applicationType = new object[]{0};
dir.Invoke("AppCreate2", applicationType);
// Save Changes
dir.CommitChanges();
folderRoot.CommitChanges();
dir.Close();
folderRoot.Close();

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top