C#操作IIS创建应用程序池出现异常:无效索引的解决方法


本文摘自PHP中文网,作者黄舟,侵删。

C#操作IIS创建应用程序池出现异常:无效索引的解决方法

相关代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

public static string CreateAppPool(string appPoolName, string frameworkVersion, string managedPipelineMode)

         {

             DirectoryEntry rootfolder = new DirectoryEntry("IIS://localhost/W3SVC/APPPOOLS");

 

             try

             {

                 DirectoryEntry appPool = rootfolder.Children.Add(appPoolName, "IIsApplicationPool");

                 if (appPool.Properties.Contains("AppPoolCommand"))

                 {

                     appPool.Properties["AppPoolCommand"][0] = "1";

                 }

                 if (appPool.Properties.Contains("ManagedRuntimeVersion"))

                 {

                     appPool.Properties["ManagedRuntimeVersion"][0] = "v4.0";

                 }

                 //以下代码在WindowsServer2008版本为6.0的系统上会出现异常:

                 //无效索引(Exception from HRESULT:0x80070585)

                 //if (appPool.Properties.Contains("AppPoolIdentityType"))

                 //{

                 //    appPool.Properties["AppPoolIdentityType"][0] = "4";

                 //}

                 if (appPool.Properties.Contains("Enable32BitAppOnWin64"))

                 {

                     appPool.Properties["Enable32BitAppOnWin64"][0] = true;

                 }

                 appPool.CommitChanges();

                 return null;

             }

             catch (System.Exception ex)

             {

                 LogToFile.Save(ex, "CreateAppPool");

                 return ex.Message;

             }

         }


将相关代码注释以后,未见对Web应用程序带来任何影响。

以上就是C#操作IIS创建应用程序池出现异常:无效索引的解决方法的详细内容!

相关阅读 >>

C#基于正则表达式抓取a标签链接和innerhtml的方法

C#实现windows剪贴板监视器的代码具体介绍

C#设计模式-观察者模式的另类的示例代码总结

C#中default什么意思

asp.net实现分页(非控件,输出html代码)

.net的优点

页面包含处理实例详解

C#实现复制和深度复制的方法详解

C#使用webclient登录网站并抓取登录后的网页信息实现方法

详解C#winform程序自动更新实现方法(图)

更多相关阅读请进入《C#》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...