5

I currently have an application written in C# that adds a website to IIS7 on the current machine and it works perfectly, the code is as follows

 var iisManager = new ServerManager();       

 var sites = iisManager.Sites;

 var site = sites.Add("WebsiteName", "C:\Website", 80);

 var application = site.Applications[0];

 application.ApplicationPoolName = appPool;

 iisManager.CommitChanges();

I have to create a version of this code that will add a website to IIS on a remote machine located on the same network. That code is as follows.

 var iisManager= ServerManager.OpenRemote("machineName"); //I've also tried machines IP 

 var sites = iisManager.Sites["Default Web Site"];

 var site =  Sites.Applications.Add("WebsiteName", "C:\Website", 80);

 site.ApplicationPoolName = appPool;

 iisManager.CommitChanges();

When machineName is the machine executing the code, it adds the website to IIS. However when machineName is the remote machine, I get the following exception

Retrieving the COM class factory for remote component with CLSID {2B72138B-3F5E-4502-8052-803546CE3364} from "remote machine name" failed due to the following error: 80070005 "remote machine"

The exception occurs when executing

var iisManager= ServerManager.OpenRemote("machineName");

Before executing the above code I use impersonation to impersonate an Administrator. I can remote into the machine and even create a file on the machine using C# code.

I assume there is an issue with permissions on the remote machine or it could be because it's a VM, I'm really not sure.

The code 80070005, is fairly general and represents restricted access but I don't understand why considering I am impersonating an Admin.

I am executing the code on a Windows 7 sp1 x64 machine and the remote VM is running Windows Server 2008 sp2 x64.

If anyone has any ideas how to fix this issue or another way to add a website to IIS on a remote machine, I'd love to hear them.

Thanks

Dan
  • 280
  • 3
  • 9
  • 1
    I believe you wiuld have to configure iis 7 manager to allow remote connections. See http://www.iis.net/learn/manage/remote-administration/remote-administration-for-iis-manager once its configured you shiuld be able to open iis 7 manager on your local machine then connect to the remote machine once tbis is working im guessing you code will. Also check the local firewall and remote firewall to make sure nothing is denied I.e. red. So check event log on both machines. It may shed some light – Kyle Aug 02 '13 at 21:08
  • Kyle, thanks for your response. It turns out my code was working however the account I was using didn't have the correct permissions because it was in a different domain. When I tested it in an environment where both machines used the same credentials and were on the same domain it worked perfectly. – Dan Aug 07 '13 at 13:06
  • It turns out my issue was with impersonation. I was impersonating with the "correct" admin credentials but because my machine and the other machine are in two different domains it was expecting DomainA.Admin and instead I was attempting to sign in with DomainB.Admin – Dan Aug 21 '13 at 20:34

1 Answers1

0

First of all you run your visual studio as administrator and OFF windows firewall of server then see it will work for Remote server