IIS management

  • Thread starter Thread starter Burak SARICA
  • Start date Start date
B

Burak SARICA

Hi there.
How can i process the folders under the default web site and do "create
application" task on spesific ones in .net with c#? (i know the names of
them.)
Thanx.
Burak SARICA
 
Burak SARICA said:
Hi there.
How can i process the folders under the default web site and do "create
application" task on spesific ones in .net with c#? (i know the names of
them.)

Burak,

You can use this code to create an IIS application:

public enum IIsInProcessFlags { InProcess, OutOfProcess, Pooled }

public void CreateApplication(string path, string name, IIsInProcessFlags
flag) {
using (DirectoryEntry entry = new DirectoryEntry(path)) {
entry.Invoke("AppCreate2", new object[1] { (int)flag });
entry.Properties["AppFriendlyName"].Value = name;
entry.CommitChanges();
}
}


hth
andrew
 
Thanx andrew.
let's say there is a directory under default web site. (not an application)
can we handle this directory? And if we can, how can we make it an
application? (Or will i only execute your code? (I couldn't try your code))


andrew lowe said:
Burak SARICA said:
Hi there.
How can i process the folders under the default web site and do "create
application" task on spesific ones in .net with c#? (i know the names of
them.)

Burak,

You can use this code to create an IIS application:

public enum IIsInProcessFlags { InProcess, OutOfProcess, Pooled }

public void CreateApplication(string path, string name, IIsInProcessFlags
flag) {
using (DirectoryEntry entry = new DirectoryEntry(path)) {
entry.Invoke("AppCreate2", new object[1] { (int)flag });
entry.Properties["AppFriendlyName"].Value = name;
entry.CommitChanges();
}
}


hth
andrew
 
Burak SARICA said:
Thanx andrew.
let's say there is a directory under default web site. (not an application)
can we handle this directory? And if we can, how can we make it an
application? (Or will i only execute your code? (I couldn't try your
code))

Burak,

Sure you can do it. To get my code to work you have to add a reference to
the System.DirectoryServices assembly, and then add a using statement to the
top of your class file:

using System.DirectoryServices;

The path variable in the method i posted points to an adsi path, not a file
system path. Note to create an iis application you must first ensure that
the IIS metabase contains an IIsWebDirectory entry for your phsyical
directory.

Try the following code:

{
CreateWebDirectory(RootAdsiPath, "YourFolderName");
CreateApplication(RootAdsiPath + "/YourFolderName", "Your friendly
application name", IIsInProcessFlags.Pooled);
}

public static string RootAdsiPath {
get { return "IIS://" + Environment.MachineName + "/W3SVC/1/Root"; }
}

public void CreateApplication(string path, string name, IIsInProcessFlags
flag) {
using (DirectoryEntry entry = new DirectoryEntry(path)) {
entry.Invoke("AppCreate2", new object[1] { (int)flag });
entry.Properties["AppFriendlyName"].Value = name;
entry.CommitChanges();
}
}

public void CreateWebDirectory(string parentPath, string name) {
if (EntryExists(parentPath + "/" + name))
return;
using (DirectoryEntry entry = new DirectoryEntry(parentPath)) {
DirectoryEntry newEntry = (DirectoryEntry)entry.Invoke("Create", new
object[2] { "IIsWebDirectory", name });
newEntry.CommitChanges();
}
}

public bool EntryExists(string path) {
try {
using (DirectoryEntry entry = new DirectoryEntry(path)) {
return entry.Guid != Guid.Empty;
}
} catch {
return false;
}
}

hth
andrew
 
Thanx very much. That's absolutely what i need.

Burak SARICA

iletide said:
Burak SARICA said:
Thanx andrew.
let's say there is a directory under default web site. (not an application)
can we handle this directory? And if we can, how can we make it an
application? (Or will i only execute your code? (I couldn't try your
code))

Burak,

Sure you can do it. To get my code to work you have to add a reference to
the System.DirectoryServices assembly, and then add a using statement to the
top of your class file:

using System.DirectoryServices;

The path variable in the method i posted points to an adsi path, not a file
system path. Note to create an iis application you must first ensure that
the IIS metabase contains an IIsWebDirectory entry for your phsyical
directory.

Try the following code:

{
CreateWebDirectory(RootAdsiPath, "YourFolderName");
CreateApplication(RootAdsiPath + "/YourFolderName", "Your friendly
application name", IIsInProcessFlags.Pooled);
}

public static string RootAdsiPath {
get { return "IIS://" + Environment.MachineName + "/W3SVC/1/Root"; }
}

public void CreateApplication(string path, string name, IIsInProcessFlags
flag) {
using (DirectoryEntry entry = new DirectoryEntry(path)) {
entry.Invoke("AppCreate2", new object[1] { (int)flag });
entry.Properties["AppFriendlyName"].Value = name;
entry.CommitChanges();
}
}

public void CreateWebDirectory(string parentPath, string name) {
if (EntryExists(parentPath + "/" + name))
return;
using (DirectoryEntry entry = new DirectoryEntry(parentPath)) {
DirectoryEntry newEntry = (DirectoryEntry)entry.Invoke("Create", new
object[2] { "IIsWebDirectory", name });
newEntry.CommitChanges();
}
}

public bool EntryExists(string path) {
try {
using (DirectoryEntry entry = new DirectoryEntry(path)) {
return entry.Guid != Guid.Empty;
}
} catch {
return false;
}
}

hth
andrew
 
Back
Top