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# 文件下载四方法

详解C#winform打开excel文档的方法总结

C#解析xml文件的代码实例分享

C#中default什么意思

asp.net在网站根目录下创建文件夹

c#cs与bs数据请求交换

C#中sealed关键字的作用详解

C#中抽象类和接口的区别

浅谈C#方法的六种参数

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

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




打赏

取消

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

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

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

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

评论

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