zoukankan      html  css  js  c++  java
  • 程序代码创建IISWEB站点

     #region 新建立一个IISWEB站点
    
            ///<summary>
            ///添加一个站点
            ///</summary>
            public string CreateWebSite()
            {
                int siteID = int.Parse(GetNewWebSiteID());
                try
                {
                    root = new DirectoryEntry("IIS://" + this._server + "/W3SVC");
                    if (EnsureNewSiteEnavaible(this._serverip + ":" + this._port + ":" + this._domain) || EnsureNewSiteEnavaible(this._server + ":" + this._port + ":" + this._domain))
                    {
                        return "该站点已经存在,请重新命名站点!";
                    }
                    else
                    {
                        DirectoryEntry site = (DirectoryEntry)root.Invoke("Create", "IIsWebServer", siteID);
                        site.Invoke("Put", "ServerComment", this._webSiteName);
                        site.Invoke("Put", "KeyType", "IIsWebServer");
                        site.Invoke("Put", "ServerBindings", this._serverip + ":" + this._port + ":" + this._domain);
                        site.Invoke("Put", "ServerState", 2);
                        site.Invoke("Put", "FrontPageWeb", 1);
                        site.Invoke("Put", "DefaultDoc", "default.aspx,index.aspx,index.html,index.htm,default.htm,default.html");
                        site.Invoke("Put", "ServerAutoStart", 1);
                        site.Invoke("Put", "ServerSize", 1);
                        site.Invoke("SetInfo");
                        site.CommitChanges();
                        root.CommitChanges();
    
                        DirectoryEntry siteVDir = site.Children.Add("Root", "IISWebVirtualDir");                 
                        siteVDir.Properties["AppIsolated"][0] = 2;
                        siteVDir.Properties["Path"][0] = this._path;
                        siteVDir.Properties["AccessFlags"][0] = 513;
                        siteVDir.Properties["FrontPageWeb"][0] = 1;
                        siteVDir.Properties["AppRoot"][0] = string.Format("/LM/W3SVC/{0}/Root", siteID);
                        siteVDir.Properties["AppFriendlyName"][0] = "默认应用程序";
                       
                     
                        PropertyValueCollection propValues = siteVDir.Properties["MimeMap"];
                        IISOle.MimeMapClass newMimeType = new IISOle.MimeMapClass();
                        newMimeType.Extension = ".flv";
                        newMimeType.MimeType = "flv-application/octet-stream";
                        propValues.Add(newMimeType);
    
                        string strerror = @"400,*,FILE,C:WINDOWShelpiisHelpcommon400.htm" +
                            @" 401,1,FILE,C:WINDOWShelpiisHelpcommon401-1.htm" +
                            @" 401,2,FILE,C:WINDOWShelpiisHelpcommon401-2.htm" +
                            @" 401,3,FILE,C:WINDOWShelpiisHelpcommon401-3.htm" +
                            @" 401,4,FILE,C:WINDOWShelpiisHelpcommon401-4.htm" +
                            @" 401,5,FILE,C:WINDOWShelpiisHelpcommon401-5.htm" +
                            @" 401,7,FILE,C:WINDOWShelpiisHelpcommon401-1.htm" +
                            @" 403,1,FILE,C:WINDOWShelpiisHelpcommon403-1.htm" +
                            @" 403,2,FILE,C:WINDOWShelpiisHelpcommon403-2.htm" +
                            @" 403,3,FILE,C:WINDOWShelpiisHelpcommon403-3.htm" +
                            @" 403,4,FILE,C:WINDOWShelpiisHelpcommon403-4.htm" +
                            @" 403,5,FILE,C:WINDOWShelpiisHelpcommon403-5.htm" +
                            @" 403,6,FILE,C:WINDOWShelpiisHelpcommon403-6.htm" +
                            @" 403,7,FILE,C:WINDOWShelpiisHelpcommon403-7.htm" +
                            @" 403,8,FILE,C:WINDOWShelpiisHelpcommon403-8.htm" +
                            @" 403,9,FILE,C:WINDOWShelpiisHelpcommon403-9.htm" +
                            @" 403,10,FILE,C:WINDOWShelpiisHelpcommon403-10.htm" +
                            @" 403,11,FILE,C:WINDOWShelpiisHelpcommon403-11.htm" +
                            @" 403,12,FILE,C:WINDOWShelpiisHelpcommon403-12.htm" +
                            @" 403,13,FILE,C:WINDOWShelpiisHelpcommon403-13.htm" +
                            @" 403,15,FILE,C:WINDOWShelpiisHelpcommon403-15.htm" +
                            @" 403,16,FILE,C:WINDOWShelpiisHelpcommon403-16.htm" +
                            @" 403,17,FILE,C:WINDOWShelpiisHelpcommon403-17.htm" +
                            @" 403,18,FILE,C:WINDOWShelpiisHelpcommon403.htm" +
                            @" 403,19,FILE,C:WINDOWShelpiisHelpcommon403.htm" +
                            @" 403,20,FILE,C:WINDOWShelpiisHelpcommon403-20.htm" +
                            @" 404,*,URL,/404.aspx" +
                            @" 404,2,FILE,C:WINDOWShelpiisHelpcommon404b.htm" +
                            @" 404,3,FILE,C:WINDOWShelpiisHelpcommon404b.htm" +
                            @" 405,*,FILE,C:WINDOWShelpiisHelpcommon405.htm" +
                            @" 406,*,FILE,C:WINDOWShelpiisHelpcommon406.htm" +
                            @" 407,*,FILE,C:WINDOWShelpiisHelpcommon407.htm" +
                            @" 412,*,FILE,C:WINDOWShelpiisHelpcommon412.htm" +
                            @" 414,*,FILE,C:WINDOWShelpiisHelpcommon414.htm" +
                            @" 415,*,FILE,C:WINDOWShelpiisHelpcommon415.htm" +
                            @" 500,12,FILE,C:WINDOWShelpiisHelpcommon500-12.htm" +
                            @" 500,13,FILE,C:WINDOWShelpiisHelpcommon500-13.htm" +
                            @" 500,15,FILE,C:WINDOWShelpiisHelpcommon500-15.htm" +
                            @" 500,16,FILE,C:WINDOWShelpiisHelpcommon500.htm" +
                            @" 500,17,FILE,C:WINDOWShelpiisHelpcommon500.htm" +
                            @" 500,18,FILE,C:WINDOWShelpiisHelpcommon500.htm" +
                            @" 500,19,FILE,C:WINDOWShelpiisHelpcommon500.htm";
                        string[] strerrorlist = strerror.Split(' ');
                        siteVDir.Properties["HttpErrors"].Value = strerrorlist;
    
                        siteVDir.Invoke("AppCreate", true);
                        root.CommitChanges();
                        siteVDir.CommitChanges();
                        site.CommitChanges();
                        return "创建站点成功!";
                    }
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
            }
            #endregion
  • 相关阅读:
    tomcat的systemctl启动脚本
    vmware中虚拟化的问题
    zabbix-3.4.14源码安装
    tomcat启动后8005端口未被占用
    Centos7初始化脚本
    CentOS7.3上如何安装Apache/2.4.34
    js完整教程一 : 基本概念和数组操作
    浅入浅出Lambda表达式
    这些基础却重要的面向对象概念,你还记得多少
    MVC5+EF6 入门完整教程11--细说MVC中仓储模式的应用
  • 原文地址:https://www.cnblogs.com/WZH75171992/p/4274330.html
Copyright © 2011-2022 走看看