简体   繁体   English

将网站添加到远程计算机C#上的IIS7

[英]Adding a website to IIS7 on remote machine C#

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 我目前有一个用C#编写的应用程序,它将一个网站添加到当前机器的IIS7上,它运行正常,代码如下

 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. 我必须创建此代码的一个版本,它将在位于同一网络上的远程计算机上将IIS添加到IIS。 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. 当machineName是执行代码的机器时,它将网站添加到IIS。 However when machineName is the remote machine, I get the following exception 但是当machineName是远程计算机时,我得到以下异常

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" 从“远程计算机名称”检索具有CLSID {2B72138B-3F5E-4502-8052-803546CE3364}的远程组件的COM类工厂失败,原因是以下错误: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. 我可以远程访问机器,甚至可以使用C#代码在机器上创建文件。

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. 我假设远程计算机上的权限存在问题,或者可能是因为它是一个VM,我真的不确定。

The code 80070005, is fairly general and represents restricted access but I don't understand why considering I am impersonating an Admin. 代码80070005,相当通用,代表限制访问,但我不明白为什么考虑我冒充管理员。

I am executing the code on a Windows 7 sp1 x64 machine and the remote VM is running Windows Server 2008 sp2 x64. 我正在Windows 7 sp1 x64计算机上执行代码,而远程VM正在运行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. 如果有人有任何想法如何解决这个问题或在远程机器上将网站添加到IIS的其他方式,我很乐意听到他们。

Thanks 谢谢

首先,您以管理员身份运行视觉工作室,然后关闭服务器的Windows防火墙,然后看它是否适用于远程服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM