当前位置: 代码迷 >> ASP.NET >> IIS创建应用程序池,代码实现网站“主目录”创建应用程序名后没有效果,有完整代码,多谢
  详细解决方案

IIS创建应用程序池,代码实现网站“主目录”创建应用程序名后没有效果,有完整代码,多谢

热度:4528   发布时间:2013-02-25 00:00:00.0
IIS创建应用程序池,代码实现网站“主目录”创建应用程序名后没有效果,有完整代码,谢谢
C# code
            #region ScriptMaps            string ScriptMaps = @".asp,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE.cer,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE.cdx,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE.asa,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE.idc,C:\WINDOWS\system32\inetsrv\httpodbc.dll,5,GET,POST.shtm,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST.shtml,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST.stm,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST.asax,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.ascx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.ashx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG.asmx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG.aspx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG.axd,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG.vsdisco,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG.rem,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG.soap,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG.config,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.cs,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.csproj,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.vb,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.vbproj,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.webinfo,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.licx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.resx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.resources,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.xoml,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG.rules,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG.master,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.skin,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.compiled,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.browser,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.mdb,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.jsl,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.vjsproj,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.sitemap,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.msgx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG.ad,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.dd,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.ldd,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.sd,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.cd,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.adprototype,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.lddprototype,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.sdm,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.sdmDocument,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.ldb,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.svc,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG.mdf,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.ldf,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.java,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.exclude,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG.refresh,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG";            String[] ScriptMapsList = System.Text.RegularExpressions.Regex.Split(ScriptMaps, "\r\n");            #endregion            const int MD_ACCESS_READ = 0x00000001; //Allow read access.            const int MD_ACCESS_SCRIPT = 0x00000200; // Allow script execution.            string appName = "CLNS";            string domain = "www.clnstest.com.cn";            string path = "C://CLNS";            string hz = "";            //创建应用程序池            DirectoryEntry apppools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");            //找出是否存在            DirectoryEntry appPool = null;            foreach (DirectoryEntry a in apppools.Children)            {                if (a.Name == appName)                {                    appPool = a;                    break;                }            }            if (appPool == null)            {                //如果不存在则进行创建                appPool = apppools.Children.Add(appName, "IIsApplicationPool");            }            appPool.Properties["AppPoolIdentityType"][0] = "2"; //网络用户            appPool.Properties["IdleTimeout"][0] = 0;   //不超时            appPool.Properties["MaxProcesses"][0] = 5;  //5进程            appPool.CommitChanges();            //创建网站            DirectoryEntry Service = new DirectoryEntry("IIS://localhost/W3SVC");            DirectoryEntry Server;            //生成网站标示            int maxID = 0;            IEnumerator ie = Service.Children.GetEnumerator();            //删除原有            while (ie.MoveNext())            {                Server = (DirectoryEntry)ie.Current;                if (Server.SchemaClassName == "IIsWebServer")                {                    if (Server.Properties["ServerComment"][0].ToString().ToLower() == domain)                    {                        Service.Children.Remove(Server);                        Service.CommitChanges();                    }                }            }            ie = Service.Children.GetEnumerator();            while (ie.MoveNext())            {                Server = (DirectoryEntry)ie.Current;                if (Server.SchemaClassName == "IIsWebServer")                {                    if (Convert.ToInt32(Server.Name) > maxID)                        maxID = Convert.ToInt32(Server.Name);                }            }            maxID++;            Server = Service.Children.Add(maxID.ToString(), "IIsWebServer");            Server.Properties["ServerComment"][0] = domain;            Server.Properties["AccessScript"][0] = true;    //脚本支持            Server.Properties["AccessRead"][0] = true;  //读取            Server.Properties["EnableDirBrowsing"][0] = false;  //目录浏览            Server.Properties["DefaultDoc"][0] = "Index.aspx,Index";   //默认文档            Server.Properties["EnableDefaultDoc"][0] = true;    //启用默认文档            Server.Properties["AccessSSL"][0] = false;  //SSL            Server.Properties["AuthAnonymous"][0] = true;  //启用匿名登录            Server.Properties["AuthNTLM"][0] = true;  //集成Windows身份验证                         var ip = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList[0].ToString();            Server.Properties["ServerBindings"].Add(ip + ":80:" + domain);            Server.CommitChanges();            DirectoryEntry root = Server.Children.Add("Root", "IIsWebVirtualDir");            root.Properties["Path"][0] = path + "\\AVA.ResourcesPlatform.WebUI" + hz;            root.Properties["AccessFlags"][0] = MD_ACCESS_READ | MD_ACCESS_SCRIPT;            root.Properties["ScriptMaps"].Value = ScriptMapsList;            root.Properties["AspEnableParentPaths"][0] = true;            root.Properties["AppRoot"][0] = "LM/W3SVC/" + maxID + "/Root";            root.Invoke("AppCreate", true);            root.CommitChanges();            //注意:AppFriendlyName必须放在root.Invoke("AppCreate", true);root.CommitChanges();之后。            root.Properties["AppFriendlyName"][0] = domain;            root.CommitChanges();            object[] param = { 0, appName, true };            root.Invoke("AppCreate3", param);            Server.Invoke("start", new object[0]);            Service.CommitChanges();
  相关解决方案