简体   繁体   English

我如何以编程方式将网站(C#)添加到IIS 6.0?

[英]How do I Programatically add a Web Site (C#) to IIS 6.0?

We have a web application that until now installed under the "Default Web Site" in IIS. 我们有一个Web应用程序,直到现在安装在IIS中的“默认网站”下。 A customer now wants us to install it under a different web site, and we want to do that from the installer. 客户现在希望我们将其安装在不同的网站下,我们希望通过安装程序进行安装。 My question is in 2 parts: A) How do I programatically add another web site alongside the 'default web site'? 我的问题分为两部分:A)如何以编程方式在“默认网站”旁边添加另一个网站? B) We are using Windows Installer - is there a way to trigger whatever code I write for section A from within the installer in time for the installation to take place at the new location? B)我们正在使用Windows Installer - 是否有办法在安装程序中及时触发我为A部分编写的代码,以便在新位置进行安装? It looks like overriding Install() is too late in the game... 看起来像覆盖Install()在游戏中为时已晚......

we use a js windows script to update our virtual directories between branches, I would imagine that you could use the same objects to create a website 我们使用js windows脚本来更新分支之间的虚拟目录,我想你可以使用相同的对象来创建一个网站

var iisPath = "IIS://localhost/W3SVC/" + siteID;
var site = GetObject(iisPath);

Microsoft has a fairly extensive article on configuring IIS 6 programatically. Microsoft有一篇关于以编程方式配置IIS 6的相当广泛的文章 As long as your MSI can call a batch file, this article should help out. 只要您的MSI可以调用批处理文件,本文应该有所帮助。

This article also has a complete script file that creates a website. 本文还有一个完整的脚本文件,用于创建网站。

Here's some C# code for programmatically creating a site: 以下是一些用于以编程方式创建网站的C#代码:

1    using System.DirectoryServices;
 2    using System;
 3    
 4    public class IISAdmin
 5    {
 6       public static int CreateWebsite(string webserver, string serverComment, string serverBindings, string homeDirectory)
 7       {
 8          DirectoryEntry w3svc = new DirectoryEntry("IIS://localhost/w3svc");
 9          
 10         //Create a website object array
 11         object[] newsite = new object[]{serverComment, new object[]{serverBindings}, homeDirectory};
 12         
 13         //invoke IIsWebService.CreateNewSite
 14         object websiteId = (object)w3svc.Invoke("CreateNewSite", newsite);
 15         
 16         return (int)websiteId;
 17      
 18      }
 19   
 20      public static void Main(string[] args)
 21      {
 22         int a = CreateWebsite("localhost", "Testing.com", ":80:Testing.com", "C:\\inetpub\\wwwroot");
 23         Console.WriteLine("Created website with ID: " + a);
 24      }
 25      
 26   }

reference: http://www.it-notebook.org/iis/article/cs_create_website_iis6.htm 参考: http//www.it-notebook.org/iis/article/cs_create_website_iis6.htm

如果您使用WiX创建MSI,请参阅此问题

Not really an expert at MSI files, but you can add a website through scripting using adsutil.vbs. 不是MSI文件的专家,但您可以使用adsutil.vbs通过脚本添加网站。 Poor man's way to handle this is to have your installer drop the files at a location without creating a website then run a later step with the script to create a website with the root at this location. 穷人处理此问题的方法是让安装人员在不创建网站的情况下将文件放在某个位置,然后使用该脚本运行后续步骤以在此位置创建具有根的网站。 Bonus points for making this optional for nudgy IIS admins like myself who hate installers touching IIS at all. 对于像我这样讨厌安装人员触摸IIS的讨厌的IIS管理员来说,这个选项是可选的。

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

相关问题 使用IIS 6.0将C#项目添加到网站 - Add C# project to a web site using IIS 6.0 如何以编程方式为IIS添加通配符筛选器? - How do I programatically add a wildcard filter for IIS? 使用C#IIS6以编程方式创建Ftp站点 - create Ftp Site programatically using C# IIS6 如何使用 C# 在 IIS 中获取网站的“浏览”URL? - How to get “Browse” URL for web site in IIS using C#? C#在asp.net项目中以编程方式在IIS中创建站点 - C# create site in IIS programatically in asp.net project 如何在 C# for Visual Studio 2022 for net6.0 的新控制台模板中添加枚举? - How do I add an enum to the new console template in C# for Visual Studio 2022 for net6.0? 如何使用C#在IIS上动态添加站点? - How to add site on IIS dynamically using C#? 如何在IIS 6.0中正确启用匿名访问并通过c#console app使用MVC Web API? - How to properly enable Anonymous Access in IIS 6.0 & consume an MVC Web API via c# console app? 如何通过C#启动/停止/查询iis应用程序(不是站点,不是应用程序池)? - How do I start/stop/query an iis application (not site, not app pool) via C#? 如何在.NET / C#中以编程方式为我的应用程序创建快捷方式(.lnk)添加快捷方式(.lnk) - How do I create add a shortcut (.lnk) for my application to the Startup folder programatically in .NET/C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM