Exemple #1
0
 /// <summary>
 /// 创建应用程序池
 /// </summary>
 /// <param name="appName">自定义引用程序池名</param>
 /// <param name="type">托管类型</param>
 /// <param name="netV">.net版本</param>
 /// <returns></returns>
 public DirectoryEntry creatAppPool(string appName, modelType type, netVersion netV)
 {
     if (!isAppPoolExist(appName))
     {
         DirectoryEntry newpool;
         DirectoryEntry appPools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
         newpool = appPools.Children.Add(appName, "IIsApplicationPool");
         //修改应用程序池配置
         setModalAndNetVersionOfappPool(appName, type, netV);
         newpool.CommitChanges();
         return(newpool);
     }
     else
     {
         return(null);
     }
 }
Exemple #2
0
        /// <summary>
        /// 设置应用程序池的托管模式和.net版本
        /// </summary>
        /// <param name="appPoolName"></param>
        /// <param name="modelType"></param>
        /// <param name="netVersion"></param>
        public void setModalAndNetVersionOfappPool(string appPoolName, modelType mt, netVersion nv)
        {
            if (String.IsNullOrEmpty(appPoolName))
            {
                return;
            }
            if (isAppPoolExist(appPoolName))
            {
                return;
            }
            if (nv == null)
            {
                return;
            }
            if (mt == null)
            {
                return;
            }
            ServerManager sm = new ServerManager();

            if (nv == netVersion.v2_0)
            {
                sm.ApplicationPools[appPoolName].ManagedRuntimeVersion = "v2.0";
            }
            else if (nv == netVersion.v4_0)
            {
                sm.ApplicationPools[appPoolName].ManagedRuntimeVersion = "v4.0";
            }

            if (mt == modelType.集成)
            {
                sm.ApplicationPools[appPoolName].ManagedPipelineMode = ManagedPipelineMode.Integrated;
            }
            else if (mt == modelType.经典)
            {
                sm.ApplicationPools[appPoolName].ManagedPipelineMode = ManagedPipelineMode.Classic; //托管模式Integrated为集成 Classic为经典
            }
            sm.CommitChanges();
        }
Exemple #3
0
        /// <summary>
        /// 创建网站
        /// </summary>
        /// <param name="siteInfo"></param>
        public DirectoryEntry creatNewWeb(newWebSiteInfo siteInfo, modelType type, netVersion netV)
        {
            DirectoryEntry Services = new DirectoryEntry("IIS://localhost/W3SVC");
            int            webID    = 0;

            foreach (DirectoryEntry server in Services.Children)
            {
                if (server.SchemaClassName == "IIsWebServer")
                {
                    if (Convert.ToInt32(server.Name) > webID)
                    {
                        webID = Convert.ToInt32(server.Name);
                    }
                }
            }
            webID++;

            //创建站点
            DirectoryEntry mySitServer = Services.Children.Add(webID.ToString(), "IIsWebServer");

            mySitServer.Properties["ServerComment"].Clear();
            mySitServer.Properties["ServerComment"].Add(siteInfo.webName);
            mySitServer.Properties["Serverbindings"].Clear();
            mySitServer.Properties["Serverbindings"].Add(":" + siteInfo.porNum + ":");
            mySitServer.Properties["Path"].Clear();                         //注意该path为站点的路径,新增站点时,两者目录一致
            mySitServer.Properties["path"].Add(siteInfo.webPath);
            mySitServer.Properties["DefaultDoc"].Add(siteInfo.defoultPage); //设置默认文档

            //创建虚拟目录
            DirectoryEntry root = mySitServer.Children.Add("Root", "IIsWebVirtualDir");

            root.Properties["path"].Clear();//该路劲属性是站点下虚拟路径的路径,类似于站点的子路径
            root.Properties["path"].Add(siteInfo.visualPath);


            if (string.IsNullOrEmpty(siteInfo.appName))
            {
                root.Invoke("appCreate", 0);
            }
            else
            {
                //创建引用程序池
                string appPoolName = siteInfo.appName;
                if (!isAppPoolExist(appPoolName))
                {
                    DirectoryEntry newpool;
                    DirectoryEntry appPools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
                    newpool = appPools.Children.Add(appPoolName, "IIsApplicationPool");
                    newpool.CommitChanges();
                }
                //修改应用程序池配置
                setModalAndNetVersionOfappPool(appPoolName, type, netV);
                root.Invoke("appCreate3", 0, appPoolName, true);
            }

            root.Properties["AppFriendlyName"].Clear();
            root.Properties["AppIsolated"].Clear();
            root.Properties["AccessFlags"].Clear();
            root.Properties["FrontPageWeb"].Clear();
            root.Properties["AppFriendlyName"].Add(root.Name);
            root.Properties["AppIsolated"].Add(2);
            root.Properties["AccessFlags"].Add(513);
            root.Properties["FrontPageWeb"].Add(1);

            root.CommitChanges();
            mySitServer.CommitChanges();

            return(mySitServer);
        }