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#将unicode编码转换为汉字字符串的代码分析

C#描述数据结构1:统计代码执行时间对象的代码详解

C#基于正则表达式去掉注释的方法示例

C#开发之winform(公共控件)

C#获取系统当前鼠标的图案示例代码

C#中dataset的用法

详细介绍C#win32控制台线程计时器代码示例

C# web应用调试开启外部访问的步骤

C# 使用npoi生成word文档(按照模板)

C#遍历文件夹子目录下所有图片及遍历文件夹下的文件代码分享

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




打赏

取消

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

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

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

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

评论

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