C # Operations IIS Create application Pool exception: Workaround for invalid index
Related code:
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["Apppoolcomman D "][0] =" 1 "; } if (AppPool.Properties.Contains ("Managedruntimeversion")) {AppPool. properties["Managedruntimeversion"][0] = "v4.0"; }//The following code will have an exception on a system with a WindowsServer2008 version of 6.0://Invalid index (Exception from hresult:0x80070585) if (AppPool.Properties.Contains ("AppPoolIdentityType"))//{//Apppool.pro perties["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; } }
The
has no effect on the Web application after commenting on the related code.