title: How do I set up a site in IIS7 on Windows 2008 Server Web SP2 via a console application?
body: <p>I have a program that I've used on Windows Server 2003 that sets up a site in IIS6 which I've used without any problems in the past.  </p>
  
  <p>I'm trying to do the same thing with Windows 2008 Server Web SP2 and I'm getting an error.  I'm guessing it has to do with the user account security.  If this is correct, is there a way that I can get around this?  Thanks.</p>
  
  <pre><code>System.Runtime.InteropServices.COMException (0x80070005): 
  Access is denied. at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
  </code></pre>
  
  <p><strong>Edit:</strong> </p>
  
  <p>I've found that Microsoft provide an assembly, <code>Microsoft.Web.Administration</code>, to make my task easier with IIS7. However I'm getting an error when I run the application. The error reported says:</p>
  
  <blockquote>
    <p>"The specified HTTPS binding is invalid".  </p>
  </blockquote>
  
  <p>I'm not specifying an https binding though so I'm not sure why I'm getting the error message. Here's the code.</p>
  
  <pre><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();
  }
  </code></pre>
  
  <p>Also, this task has to update multiple servers in a web farm.  Does anyone know how to modify the code to make this happen?</p>