M
Marshall
I've created a web service in c# that configures IIS using Directory
Services. In order create and configure IIS sites the web service needs to
run with admin privileges so in my web service web.cofig file I impersonate a
system account with the appropriate privileges.
<identity impersonate="true" userName="domain\account" password="pwd" />
Opening my web service locally works. Sites are created just fine through
the test interface. My problem is consuming this web service remotely
through an ASP.NET app. Other web methods work, like a simple hello world
method, but I get an access denied error when calling the method that
configures IIS.
Any help would be great. Thanks - Marshall
[WebMethod]
public int CreateSite2k3(string webserver, string serverComment, string
serverBindings, string homeDirectory)
{
// code taken from: http://www.gafvert.info/notes/CreateWebsiteIIS6.htm
DirectoryEntry w3svc = new DirectoryEntry("IIS://" + webserver + "/w3svc");
//Create a website object array
object[] newsite = new object[]{serverComment, new object[]{serverBindings},
homeDirectory};
//invoke IIsWebService.CreateNewSite
object websiteID = (object)w3svc.Invoke("CreateNewSite", newsite);
// set the AppFriendlyName property
DirectoryEntry newRoot = new DirectoryEntry("IIS://" + webserver + "/w3svc/"
+ websiteID.ToString() + "/ROOT");
newRoot.Properties["AppFriendlyName"][0] = "Default Application";
newRoot.CommitChanges();
return (int)websiteID;
}
Services. In order create and configure IIS sites the web service needs to
run with admin privileges so in my web service web.cofig file I impersonate a
system account with the appropriate privileges.
<identity impersonate="true" userName="domain\account" password="pwd" />
Opening my web service locally works. Sites are created just fine through
the test interface. My problem is consuming this web service remotely
through an ASP.NET app. Other web methods work, like a simple hello world
method, but I get an access denied error when calling the method that
configures IIS.
Any help would be great. Thanks - Marshall
[WebMethod]
public int CreateSite2k3(string webserver, string serverComment, string
serverBindings, string homeDirectory)
{
// code taken from: http://www.gafvert.info/notes/CreateWebsiteIIS6.htm
DirectoryEntry w3svc = new DirectoryEntry("IIS://" + webserver + "/w3svc");
//Create a website object array
object[] newsite = new object[]{serverComment, new object[]{serverBindings},
homeDirectory};
//invoke IIsWebService.CreateNewSite
object websiteID = (object)w3svc.Invoke("CreateNewSite", newsite);
// set the AppFriendlyName property
DirectoryEntry newRoot = new DirectoryEntry("IIS://" + webserver + "/w3svc/"
+ websiteID.ToString() + "/ROOT");
newRoot.Properties["AppFriendlyName"][0] = "Default Application";
newRoot.CommitChanges();
return (int)websiteID;
}