An Exception occurred when using C # To operate IIS to create an application pool: Invalid index (Exception from HRESULT: 0x80070585)
Related code:
[Csharp]
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 ";
}
// The following code indicates that an exception occurs on a Windows Server 6.0 system:
// Invalid index (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;
}
}
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 ";
}
// The following code indicates that an exception occurs on a Windows Server 6.0 system:
// Invalid index (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;
}
}
After the relevant code is commented out, there is no impact on the Web application.