日期:2014-05-17  浏览次数:20497 次

IIS创建应用程序池,设置相关属性
用DirectoryEntry创建应用程序池后,如何可以设置该任务的.net版本,还有托管管道模式啊??

我创建完的新的应用程序池后,默认.net为2.0,管道模式经典。。


怎么可以用代码修改啊?

------解决方案--------------------
代码修改多麻烦啊,建议直接在iis虚拟路径或网站属性中修改……
------解决方案--------------------
看错了。。是用DirectoryEntry创建


// .NET对应属性如下,其中de为虚拟目录对应的DirectoryEntry对象
de.Properties["UNCUserName"][0] = 账户字符串; // Web服务器桥接文件服务器的UNC账户
de.Properties["UNCPassword"][0] = 密码字符串; // Web服务器桥接文件服务器的UNC账户密码
 
//【ASP.NET】
ScriptMaps[0] =.asp,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
……
ScriptMaps[50] =.refresh,C:\windows\Microsoft.NET\Framework\v2.0.50727\aspnet_is
api.dll,5,GET,HEAD,POST,DEBUG




tring HostName = "localhost";
string newSiteNum = "2";
string Path = String.F"localhost";ormat("IIS://{0}/w3svc/{1}/root",HostName,newSiteNum);
DirectoryEntry root = new DirectoryEntry(Path);

NewWebSiteInfoAll newweb = new NewWebSiteInfoAll();
ArrayList arl = new ArrayList();
arl.Add(@".rem,D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG");
arl.Add(@".asax,D:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
root.Properties["s criptMaps"].Value = arl.ToArray();
root.CommitChanges();
不懂是不是楼主要的
------解决方案--------------------
改.net 版本看看这个, IIS6下得,不清楚IIS7下是否工作:

IIS 6.0 DirectoryEntry ScriptMaps property and set .Net version
http://stackoverflow.com/questions/1299084/iis-6-0-directoryentry-scriptmaps-property-and-set-net-version
------解决方案--------------------
这个是修改IIS7的Managed Pipeline mode 的代码:
C# code

static void Main(string[] args)
        {
            string propertyName = "ManagedPipelineMode";
            int mode = -1;

            if (args.Length < 2 || string.Compare(args[0], "/?") == 0 || string.Compare(args[0].ToLower(), "/help") == 0)
            {
                ShowHelp();
                return;
            }

            string appPoolName = args[0];
            string pipeLineMode = args[1].ToLower();

            switch (pipeLineMode)
            {
                case "classic":
                    mode = 1;
                    break;
                case "integrated":
                    mode = 0;
                    break;
                default:
                    mode = -1;
                    break;
            }

            if (mode == -1)
            {
                ShowHelp();
                return;
            }

            DirectoryEntry poolRoot = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");

            try
            {
                DirectoryEntry pool = poolRoot.Children.Find(appPoolName, "IIsApplicationPool");
                pool.InvokeSet(propertyName, mode);
                pool.CommitChanges();
            }
            catch (DirectoryNotFoundException ex)
            {
                Console.WriteLine("Application pool name was not found.");
                Console.WriteLine(ex.Message);
            }
            catch (COMException ex)
            {
                Console.WriteLine("Error in changing property \"" + propertyName + "\" of Application Pool \"" + appPoolName + "\"");
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unknown error.");
                Console.WriteLine(ex.Message);
            }
        }

        private static void ShowHelp()
        {
            Console.Wr