简体   繁体   English

单独的IIS绑定用于应用程序

[英]separate IIS binding for application

I am trying to deploy a website by using program IN IIS 7 using c#. 我正在尝试使用c#在IIS 7中使用程序来部署网站。

i want to deploy the application under Default website. 我想在默认网站下部署该应用程序。

the application should have a different port number (90) that is separate from other applications under Default website or even the default port number of Default website( ie, 8080 ). 该应用程序应具有与默认网站下的其他应用程序不同的端口号(90),甚至应与默认网站的默认端口号( 即8080 )分开。

I am trying to do this pro grammatically using ServerManager class without specifying any binding information in the web.config file of website. 我正在尝试使用ServerManager类在程序上进行此操作,而不在网站的web.config文件中指定任何绑定信息。

static void CreateSite()
    {
        using (ServerManager server = new ServerManager())
        {
            if (server.Sites != null && server.Sites.Count > 0)
            {
                Site defaultsite=server.Sites.FirstOrDefault(s => s.Name == "Default Web Site");
                if (defaultsite != null)
                {
                    string path = @"C:\inetpub\wwwroot\MyApp\";

                    //specify the Binding information
                    string ip = "*";
                    string port = "90";
                    string hostName = "*";


                    string bindingInfo = string.Format(@"{0}:{1}:{2}", ip, port, hostName);
                    defaultsite.Applications.Add("/MyApp", path);

                 server.CommitChanges();
                }
            }
        }
    }

ServerManager class allows us to create/update/delete bindings for each site rather than for each application under a site as below. ServerManager类允许我们为每个站点而不是如下站点的每个应用程序创建/更新/删除绑定。

                    string ip = "*";
                    string port = "90";
                    string hostName = "*";


                    string bindingInfo = string.Format(@"{0}:{1}:{2}", ip, port, hostName);
                    BindingCollection bindingCollection = defaultsite.Bindings;
                    Binding binding = defaultsite.Bindings.CreateElement("binding");
                    binding["protocol"] = "http";
                    binding["bindingInformation"] = bindingInfo;
                    bindingCollection.Add(binding);
                    server.CommitChanges();

How do i specify a different port number for the application in IIS 7.0 using ServerManager class methods? 如何使用ServerManager类方法为IIS 7.0中的应用程序指定其他端口号?

You can create a new web site and assign it to a port number of your choice. 您可以创建一个新网站并将其分配给您选择的端口号。 Under that web site, you can configure your application. 在该网站下,您可以配置应用程序。

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

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