简体   繁体   English

如何通过控制台应用程序在Windows 2008 Server Web SP2的IIS7中设置站点?

[英]How do I set up a site in IIS7 on Windows 2008 Server Web SP2 via a console application?

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. 我有一个在Windows Server 2003上使用过的程序,该程序在IIS6中设置了一个我过去使用过的站点,而过去没有任何问题。

I'm trying to do the same thing with Windows 2008 Server Web SP2 and I'm getting an error. 我正在尝试使用Windows 2008 Server Web SP2做同样的事情,但出现错误。 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. 谢谢。

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

Edit: 编辑:

I've found that Microsoft provide an assembly, Microsoft.Web.Administration , to make my task easier with IIS7. 我发现Microsoft提供了一个程序集Microsoft.Web.Administration ,使IIS7可以使我的任务更加轻松。 However I'm getting an error when I run the application. 但是,运行应用程序时出现错误。 The error reported says: 报告的错误说:

"The specified HTTPS binding is invalid". “指定的HTTPS绑定无效”。

I'm not specifying an https binding though so I'm not sure why I'm getting the error message. 我没有指定https绑定,所以我不确定为什么会收到错误消息。 Here's 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();
}

Also, this task has to update multiple servers in a web farm. 同样,此任务必须更新Web场中的多个服务器。 Does anyone know how to modify the code to make this happen? 有谁知道如何修改代码来实现这一目标?

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

Remove the domain, if you're like me you didn't add the second ':' after the port 删除域,如果您像我一样,则没有在端口后添加第二个“:”

To use the Microsoft.Web.Administration API to create and manipulate IIS on a remote server you can use the ServerManager.OpenRemote(string serverName) method. 若要使用Microsoft.Web.Administration API在远程服务器上创建和操作IIS,可以使用ServerManager.OpenRemote(string serverName)方法。

However I've a feeling you probably need to run this in the context of an Active Directory user with the correct rights on the remote server as there is no way of providing credentials for the remote server. 但是我感觉您可能需要在具有正确权限的Active Directory用户的上下文中运行此服务器,因为无法为远程服务器提供凭据。

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

相关问题 在 IIS 7 Windows Server 2008 R2 Enterprise SP2 上激活 MVC Web 站点 - Activate MVC Web site on IIS 7 Windows Server 2008 R2 Enterprise SP2 .net-core 2.2 与 windows server 2008 sp2 兼容吗? - Is .net-core 2.2 compatible with windows server 2008 sp2? 如何在Windows XP SP2的IIS中运行.aspx页 - How to run .aspx page in IIS on Windows XP SP2 在Windows Server 2008 SP2 64位上使用库时出错 - Error using the Library on a Windows Server 2008 SP2 64-bit 导出到Excel-Windows Server 2008 IIS7上的问题 - Export to excel - Issue on Windows Server 2008 IIS7 如何以编程方式在IIS7中启动/停止默认网站和应用程序池 - How to Start/Stop Default Web Site and Application Pools in IIS7 programmatically 在一个项目中如何设置“客户端”控制台应用程序和“服务器”控制台应用程序 - In a project how to set up a “client” console application and a “server” console application 如何通过C#启动/停止/查询iis应用程序(不是站点,不是应用程序池)? - How do I start/stop/query an iis application (not site, not app pool) via C#? 设置SPN以从IIS7以原始用户身份访问SQL Server 2008 - Setting up SPN to access SQL Server 2008 as original user from IIS7 如何使用Microsoft.Web.Administration命名空间在IIS7中干净地操作Handler Mappings? - How do I manipulate Handler Mappings cleanly in IIS7 using the Microsoft.Web.Administration namespace?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM