我有一个简单的C#应用程序,用于安装和配置我们的Web服务。其中一部分涉及使用输入到安装程序的命令行参数设置应用程序池标识属性。为此,我在自定义操作中使用了以下代码:
using (System.DirectoryServices.DirectoryEntry appPools = new System.DirectoryServices.DirectoryEntry("IIS://Localhost/W3SVC/AppPools"))
{
System.DirectoryServices.DirectoryEntry myAppPool = appPools.Children.Find("SomeAppPool", "IIsApplicationPool");
myAppPool.Properties["AppPoolIdentityType"].Value = 3;
myAppPool.Properties["WAMUserName"].Value = "SomeUserName";
myAppPool.Properties["WAMUserPass"].Value = "SomePassword";
myAppPool.Invoke("SetInfo", null);
myAppPool.CommitChanges();
}
我们发现,在较新的计算机上,该代码将以COM Exception 0x80005000
出现错误,除非
"IIS Metabase and IIS 6 configuration compatablility"
功能已安装(即必须启用"Control Panel->Programs and Features->Turn Windows features on or off->Internet Information Services->Web Management Tools->IIS 6 Management Compatibility->IIS 6 Metabase and IIS 6 configuration compatibility"
)。
由于在IIS 6之后似乎已放弃了这种更新应用程序池标识的方法,这是否意味着存在一种更新或更现代的方法来更新IIS应用程序池的Identity属性?我已经在Google上进行了广泛的搜索,使用System.DirectoryServices.DirectoryEntry命名空间似乎是我发现使用C#以编程方式设置应用程序池标识的唯一方法。
我可以使用此代码并要求安装"IIS Metabase and IIS 6 configuration compatablility"
,但是如果不赞成使用此代码,而希望使用较新的方法,那么我宁愿仅使用较新的方法。