G
Gabriel R
I am trying to create a virtual directory using ADSI, with the following
C# code:
string Server = <srv>;
string ApplicationName = <app>;
DirectoryEntry root = new DirectoryEntry("IIS://" + Server +
"/W3SVC/1/Root", adminusername, adminuserpass);
// look up the virtual dir
DirectoryEntry app = null;
foreach (DirectoryEntry e in root.Children)
{
if (e.SchemaClassName == "IISWebVirtualDir" && e.Name.ToUpper() ==
ApplicationName.ToUpper())
{
app = e; break;
}
}
if (app == null)
{
// create the virtual dir
app = root.Children.Add(ApplicationName, "IISWebVirtualDir");
}
// create the application attached to it
app.Invoke("AppCreate", false);
// set the properties of the virtual dir
app.Properties["Path"][0] = "D:\\Web";
app.Properties["DefaultDoc"][0] = "default.aspx";
app.Properties["AppFriendlyName"][0] = ApplicationName;
app.CommitChanges();
The code works fine if I run it from a Windows Forms application,
however if it's run from a web application I get a COMException: Access
denied.
The web application runs under the credentials of the admin user (I used
<identity impersonate=true ...> in web.config).
How could I solve this problem?
Gabriel
C# code:
string Server = <srv>;
string ApplicationName = <app>;
DirectoryEntry root = new DirectoryEntry("IIS://" + Server +
"/W3SVC/1/Root", adminusername, adminuserpass);
// look up the virtual dir
DirectoryEntry app = null;
foreach (DirectoryEntry e in root.Children)
{
if (e.SchemaClassName == "IISWebVirtualDir" && e.Name.ToUpper() ==
ApplicationName.ToUpper())
{
app = e; break;
}
}
if (app == null)
{
// create the virtual dir
app = root.Children.Add(ApplicationName, "IISWebVirtualDir");
}
// create the application attached to it
app.Invoke("AppCreate", false);
// set the properties of the virtual dir
app.Properties["Path"][0] = "D:\\Web";
app.Properties["DefaultDoc"][0] = "default.aspx";
app.Properties["AppFriendlyName"][0] = ApplicationName;
app.CommitChanges();
The code works fine if I run it from a Windows Forms application,
however if it's run from a web application I get a COMException: Access
denied.
The web application runs under the credentials of the admin user (I used
<identity impersonate=true ...> in web.config).
How could I solve this problem?
Gabriel