C # An Exception occurred when operating IIS to create an application pool: Invalid index (Exception from HRESULT: 0x80070585)

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.