狠狠色丁香婷婷综合尤物/久久精品综合一区二区三区/中国有色金属学报/国产日韩欧美在线观看 - 国产一区二区三区四区五区tv

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

【C#】ServerManager更改IIS7設(shè)置

admin
2021年5月11日 16:18 本文熱度 4493

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Web.Administration;

namespace IIS自動安裝程序_控制臺版v1._0_20100727_zch
{
    public class IIS7Core1
    {
        /// <summary>
        /// 創(chuàng)建站點
        /// </summary>
        /// <param name="siteName">站點名稱</param>
        /// <param name="bindingInfo">綁定<example>"*:80:myhost.com"</example></param>
        /// <param name="physicalPath">物理路徑</param>
        /// <param name="pathToResourceFile">資源路徑</param>
        /// <param name="pathTo公用上傳">資源路徑</param>
        /// <param name="password">FileUser密碼</param>
        /// <param name="defaultDocName">默認首頁</param>
        public static void Create(string siteName, string bindingInfo, string physicalPath, string pathToResourceFile, string pathTo公用上傳, string password, string defaultDocName)
        {
            //Delete an existent web site.
            ServerManager iisManager = new ServerManager();
            Site site = iisManager.Sites[siteName];
            if (site != null)
            {
                iisManager.Sites.Remove(site);
                iisManager.CommitChanges();
            }

            //Delete an existent web site app pool.
            iisManager = new ServerManager();
            ApplicationPool oldpool = iisManager.ApplicationPools[siteName + "Pool"];
            if (oldpool != null)
            {
                iisManager.ApplicationPools.Remove(oldpool);
                iisManager.CommitChanges();
            }

            iisManager = new ServerManager();
            //創(chuàng)建站點
            iisManager.Sites.Add(siteName, "http", bindingInfo, physicalPath);
            if (true)
            {
                //創(chuàng)建應(yīng)用程序池
                ApplicationPool pool = iisManager.ApplicationPools.Add(siteName + "Pool");

                //設(shè)置應(yīng)用程序池標(biāo)識
                pool.ProcessModel.IdentityType = ProcessModelIdentityType.ApplicationPoolIdentity;

                //if (!String.IsNullOrEmpty(appPoolUserName))
                //{
                //    pool.ProcessModel.UserName = appPoolUserName;
                //    pool.ProcessModel.Password = appPoolPassWord;
                //}

                //設(shè)置應(yīng)用程序池的托管管道模式
                pool.ManagedPipelineMode = ManagedPipelineMode.Classic;

                //設(shè)置應(yīng)用程序池的.net版本
                pool.ManagedRuntimeVersion = "v4.0";

                //設(shè)置應(yīng)用程序池的名稱
                iisManager.Sites[siteName].Applications["/"].ApplicationPoolName = pool.Name;
            }
            //將一個應(yīng)用程序(Application)添加到一個站點
            //iisManager.Sites[siteName].Applications.Add("/" + siteName, physicalPath);

            //建立虛擬目錄(Virtual Directory)
            Application app = iisManager.Sites[siteName].Applications[0];

            if (siteName.ToLower().Contains("web"))
            {
                //虛擬目錄
                app.VirtualDirectories.Add("/ResourceFile", pathToResourceFile);
                app.VirtualDirectories.Add("/UploadCenter", pathTo公用上傳);
                app.VirtualDirectories.Add("/UploadFile", pathTo公用上傳);

                //設(shè)置每個虛擬目錄的認證
                app.VirtualDirectories["/ResourceFile"].UserName = "FileUser";
                app.VirtualDirectories["/ResourceFile"].Password = password;
                app.VirtualDirectories["/UploadCenter"].UserName = "FileUser";
                app.VirtualDirectories["/UploadCenter"].Password = password;
                app.VirtualDirectories["/UploadFile"].UserName = "FileUser";
                app.VirtualDirectories["/UploadFile"].Password = password;

            }
            else if (siteName.ToLower().Contains("sdzn"))
            {
                app.VirtualDirectories.Add("/Upload", pathTo公用上傳);
                app.VirtualDirectories["/Upload"].UserName = "FileUser";
                app.VirtualDirectories["/Upload"].Password = password;
            }

            else//wcf
            {
                app.VirtualDirectories.Add("/ResourceFile", pathToResourceFile);
                app.VirtualDirectories.Add("/UploadFile", pathTo公用上傳);
                app.VirtualDirectories["/ResourceFile"].UserName = "FileUser";
                app.VirtualDirectories["/ResourceFile"].Password = password;
                app.VirtualDirectories["/UploadFile"].UserName = "FileUser";
                app.VirtualDirectories["/UploadFile"].Password = password;
            }

            iisManager.CommitChanges();

            //在站點上添加默認文檔
            iisManager = new ServerManager();
            Configuration cfg = iisManager.GetWebConfiguration(siteName);
            ConfigurationSection defaultDocumentSection = cfg.GetSection("system.webServer/defaultDocument");
            ConfigurationElement filesElement = defaultDocumentSection.GetChildElement("files");
            ConfigurationElementCollection filesCollection = filesElement.GetCollection();

            foreach (ConfigurationElement elt in filesCollection)
            {
                if (elt.Attributes["value"].Value.ToString() == defaultDocName)
                {
                    return;
                }
            }

            try
            {
                ConfigurationElement docElement = filesCollection.CreateElement();
                docElement.SetAttributeValue("value", defaultDocName);
                filesCollection.Add(docElement);
            }
            catch (Exception) { }   //this will fail if existing

            iisManager.CommitChanges();
        }
    }
}


該文章在 2021/5/11 16:18:22 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務(wù)費用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務(wù)都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved