How to configure a site in IIS7 on Windows 2008 Server Web SP2 through a console application?

I have a program that I used in Windows Server 2003 that sets up a site in IIS6 that I used without any problems in the past.

I am trying to do the same with Windows 2008 Server Web SP2 and I am getting an error. I assume this is due to the security of the user account. If this is correct, is there a way I can get around this? Thank.

System.Runtime.InteropServices.COMException (0x80070005): 
Access is denied. at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)

Edit:

I found that Microsoft provides an assembly Microsoft.Web.Administrationto simplify my task using IIS7. However, I get an error when starting the application. The error reported says:

"The specified HTTPS binding is invalid."

I do not specify an https binding, although I am not sure why I am getting an error. Here is the code.

using Microsoft.Web.Administration;
....
using (ServerManager iisManager = new ServerManager())
{
  iisManager.Sites.Add(site.Name.ToString(), "http", "*:80:" + domain, 
                          server.InetPath + site.Name);
  iisManager.CommitChanges();
  Site newSite = iisManager.Sites[site.Name];
  newSite.Applications[0].ApplicationPoolName = "TrialUsers";
  iisManager.CommitChanges();
}

In addition, this task should update several servers in the web farm. Does anyone know how to change the code to make this happen?

+5
source share
2 answers
iisManager.Sites.Add(site.Name.ToString(), "http:", "*:80:" + domain, 
                     server.InetPath + site.Name);

Delete the domain, if you look like me, you did not add a second ":" after the port

+5
source

To use the API Microsoft.Web.Administrationto create and manage IIS on a remote server, you can use the method ServerManager.OpenRemote(string serverName).

However, I feel that you probably need to run this in the context of an Active Directory user with the correct permissions on the remote server, since there is no way to provide credentials for the remote server.

0

All Articles