C#操作IIS創建應用程序池出現異常:無效索引(Exception from HRESULT:0x80070585)
相關代碼:
01.public static string CreateAppPool(string appPoolName, string frameworkVersion, string managedPipelineMode)
02. {
03. DirectoryEntry rootfolder = new DirectoryEntry("IIS://localhost/W3SVC/APPPOOLS");
04.
05. try
06. {
07. DirectoryEntry appPool = rootfolder.Children.Add(appPoolName, "IIsApplicationPool");
08. if (appPool.Properties.Contains("AppPoolCommand"))
09. {
10. appPool.Properties["AppPoolCommand"][0] = "1";
11. }
12. if (appPool.Properties.Contains("ManagedRuntimeVersion"))
13. {
14. appPool.Properties["ManagedRuntimeVersion"][0] = "v4.0";
15. }
16. //以下代碼在WindowsServer2008版本為6.0的系統上會出現異常:
17. //無效索引(Exception from HRESULT:0x80070585)
18. //if (appPool.Properties.Contains("AppPoolIdentityType"))
19. //{
20. // appPool.Properties["AppPoolIdentityType"][0] = "4";
21. //}
22. if (appPool.Properties.Contains("Enable32BitAppOnWin64"))
23. {
24. appPool.Properties["Enable32BitAppOnWin64"][0] = true;
25. }
26. appPool.CommitChanges();
27. return null;
28. }
29. catch (System.Exception ex)
30. {
31. LogToFile.Save(ex, "CreateAppPool");
32. return ex.Message;
33. }
34. }
將相關代碼注釋以後,未見對Web應用程序帶來任何影響。
URL:http://www.bianceng.cn/Programming/csharp/201410/45785.htm