简体   繁体   English

IIS7添加新的网站/主机头ASP.NET Web表单

[英]IIS7 Add New Website / Host Header ASP.NET Web Form

How can I either create a new website or add a host header to an existing IIS 7 server from code? 如何创建新网站或从代码向现有IIS 7服务器添加主机头?

I have looked and have not been able to find a working example? 我已经看过,但是找不到一个可行的例子?

One solution would be to create a custom HttpModule that does the work for you, however it does require you to be have a DNS that supports wildcards (*). 一种解决方案是创建一个可以为您完成工作的自定义HttpModule,但是它确实要求您具有支持通配符(*)的DNS。 If your DNS does not support that, you might look into managing your own DNS. 如果您的DNS不支持,则可以考虑管理自己的DNS。

That said, here's a good post on creating an HttpModule that parses the "subdomain" passed in and forwards the traffic to the appropriate spot. 就是说,这是创建HttpModule的好文章,该HttpModule解析传入的“子域”并将流量转发到适当的位置。 He's using a search mechanism [to locate content with keywords matching the subdomain], but it can be modified for you own needs. 他正在使用一种搜索机制[通过与子域匹配的关键字来定位内容],但是可以根据您自己的需要对其进行修改。

http://codebetter.com/blogs/brendan.tompkins/archive/2006/06/27/146875.aspx http://codebetter.com/blogs/brendan.tompkins/archive/2006/06/27/146875.aspx

[EDIT] Another solution would be to find a DNS provider that offers a programmable DNS service, perhaps through a web service. [编辑]另一个解决方案是找到可能通过Web服务提供可编程DNS服务的DNS提供程序。 You would then programatically add a subdomain to that DNS when needed from your application. 然后,您可以在需要时从应用程序中以编程方式将子域添加到该DNS。 That's a super simplified explanation, and doesn't take into account your business needs. 这是一个超级简化的解释,并且没有考虑您的业务需求。 Personally I prefer the HttpModule option for adding subdomains within an application as it requires less modification of the server(s) involved. 我个人更喜欢使用HttpModule选项在应用程序中添加子域,因为它需要对所涉及的服务器进行较少的修改。

What version of .Net are you using? 您正在使用哪个版本的.Net?

If you are using .Net 3.0 or 3.5, and if you only need to configure IIS7 (not 6 or 5), check out the Microsoft.Web.Administration namespace -- it should have everything you need. 如果您使用的是.Net 3.0或3.5,并且仅需要配置IIS7(而不是6或5),请签出Microsoft.Web.Administration命名空间-它应具有所需的一切。

If you are using an older version of .net, have a look at WMI. 如果使用的是.net的旧版本,请查看WMI。

I don't have any WMI code for IIS 7 (we have a setup for an intranet application, but it uses IIS 6-compatible WMI). 我没有针对IIS 7的任何WMI代码(我们为Intranet应用程序进行了设置,但它使用了与IIS 6兼容的WMI)。 But, here's a link to a tool you can use for figuring out the WMI stuff: http://www.microsoft.com/downloads/details.aspx?familyid=2cc30a64-ea15-4661-8da4-55bbc145c30e&displaylang=en It will actually generate c# (or vb.net) code for manipulating WMI. 但是,这是您可以用来弄清楚WMI内容的工具的链接: http : //www.microsoft.com/downloads/details.aspx? familyid=2cc30a64-ea15-4661-8da4-55bbc145c30e&displaylang=en生成用于操纵WMI的C#(或vb.net)代码。 For IIS 7, I think that the root WMI namespace is root\\WebAdministration. 对于IIS 7,我认为根WMI命名空间是root \\ WebAdministration。

Also, have a look at this link, it might help Get to Know the IIS 7.0 WMI Provider Using CIM Studio 另外,请查看此链接,它可能会帮助您使用CIM Studio了解IIS 7.0 WMI提供程序

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

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