使用Microsoft.Web.Administration 自动配置网站到IIS

不必多说,看代码:

注意:ip的设置                string fullIP = ip + ":" + port + ":";

至于如何删除网站就可想而知

/// <summary>
        /// create web site in IIS
        /// </summary>
        /// <param name="websiteName">站点名</param>
        /// <param name="physicsPath">物理路径</param>
        /// <param name="ip">ip地址</param>
        /// <param name="port">端口号</param>
        /// <param name="poolver">应用程序池的DOTNET FRAMEWORK版本</param>
        /// <param name="binding">使用的协议</param>
        public void CreateWebSite(string websiteName, string physicsPath,
            string port, string ip = "*", string poolver = "v4.0", string binding = "http")
        {
            try
            {
                string fullIP = ip + ":" + port + ":";
                ServerManager iisManager = new ServerManager();
                ApplicationPool newPool = iisManager.ApplicationPools.Add(websiteName);
                newPool.ManagedRuntimeVersion = poolver;

                Site mySide = iisManager.Sites.Add(websiteName, binding, fullIP, physicsPath);
                mySide.Applications[0].ApplicationPoolName = websiteName;

                iisManager.CommitChanges();
            }
            catch (Exception error)
            {



            }
         
        }

你可能感兴趣的:(使用Microsoft.Web.Administration 自动配置网站到IIS)