简体   繁体   English

如何使用IIS7和C#NET和其他设置创建网站

[英]how to create a website with IIS7 and C# NET and other settings

We have some setup scripts that create websites when our game servers are installed. 我们有一些安装脚本,可以在安装游戏服务器时创建网站。 I have a different type of game that I need to do this for, so I am tinkering with C# NET to get the job done. 我需要为此执行其他类型的游戏,因此我正在修补C#NET以完成任务。 I don't know too much about IIS so I am hoping for help. 我对IIS不太了解,因此希望获得帮助。

This is what I have code wise so far. 到目前为止,这是我的明智代码。 What I need to do is have it create the website so it is accessible via %ip%/%ip%-%port% (of course these will be replaced by the IP/Port) and have that point to %gameserverroot%httpredirect. 我需要做的是让它创建网站,以便可以通过%ip%/%ip%-%port%(当然这些将由IP /端口代替)进行访问,并将其指向%gameserverroot%httpredirect。

Also, is there any way to verify that Directory Browsing is turned on via C#, and turn it on if it isn't? 此外,是否有任何方法可以验证是否通过C#打开了目录浏览,如果没有,请打开它吗?

Any help I can would be much appreciated. 我能提供的任何帮助将不胜感激。 A lot of the IIS7 with C# NET examples are pretty confusing. 许多带有C#NET示例的IIS7都令人困惑。 I have found some information on Stackoverflow, but not enough to complete this. 我已经找到有关Stackoverflow的一些信息,但还不足以完成此操作。

Thanks! 谢谢!

NOTE: I am answering just the directory browse question as you didn't paste any code (that I could see) to show what you currently have. 注意:我只回答目录浏览问题,因为您没有粘贴任何代码(我可以看到)来显示您当前拥有的内容。 This example may help you, and if not, please post your full code and I can try to expand my example 本示例可能会对您有所帮助,否则,请发布您的完整代码,我可以尝试扩展我的示例


Use System.Web.Administration namespace (IIS 7), something like this should work: 使用System.Web.Administration命名空间(IIS 7),类似这样的方法应该起作用:

(I'm assuming your webSite name is "TestSite", but its really whatever you call it. Just set that to the site name you create) (我假设您的webSite名称为“ TestSite”,但实际上您叫它什么名称。只需将其设置为您创建的网站名称即可)

using(ServerManager serverManager = new ServerManager()) {
   Configuration config = serverManager.GetWebConfiguration("TestSite");

   ConfigurationSection directoryBrowseSection =  
       config.GetSection("system.webServer/directoryBrowse");


   if(directoryBrowseSection["enabled"] != true)
   {
      directoryBrowseSection["enabled"] = true;
   }

   serverManager.CommitChanges();
}

the If(!enabled){} check/loop isn't required, just showing to answer your exact question. 不需要If(!enabled){}检查/循环,仅显示回答您的确切问题。 You can set to enabled = true without the check for simplicity 您可以设置为enabled = true,而无需进行简单性检查


Anytime you run into confusion surrounding IIS 7, you should consult the iis7 site. 每当您对IIS 7感到困惑时,都应查询iis7站点。 http://www.iis.net/ http://www.iis.net/

It is one of the best (imo) product reference guides out there. 它是目前最好的(imo)产品参考指南之一。

Remember in IIS7 everything is controlled by a series of XML files, so everything else is simply changing these. 请记住,在IIS7中,所有内容都由一系列XML文件控制,因此其他所有内容都只是在更改这些文件。 One way to approach programmatic development is to figure out how you'd do it in a web.config and then consult the IIS.net site's config reference for that section. 进行程序开发的一种方法是弄清楚如何在web.config中进行该工作,然后在该部分中查阅IIS.net站点的配置参考。 The section pages almost always contains both the XML version AND the C# approach for modification. 章节页面几乎总是包含XML版本和C#修改方法。 The above code is mostly from the IIS page on the directoryBrowse configuration section, for example. 例如,上面的代码主要来自IIS页面的directoryBrowse配置部分。

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

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