Question

I am creating an application pool for IIS 6 (Windows Server 2003R2) programmatically using the following code, but getting an error on the line that is trying to set the ManagedPipelineMode

Attempt 1

        string metabasePath = @"IIS://localhost/W3SVC/AppPools";

        DirectoryEntry apppools = new DirectoryEntry(metabasePath);
        DirectoryEntry newpool = apppools.Children.Add(AppPoolName, "IIsApplicationPool");
        newpool.Properties["managedRuntimeVersion"].Value = "v4.0";
        newpool.InvokeSet("ManagedPipelineMode", new Object[] { 0 }); //exception thrown on this line
        newpool.Properties["Enable32BitAppOnWin64"].Value = true;
        if (!string.IsNullOrEmpty(username))
        {
            newpool.Properties["AppPoolIdentityType"].Value = 3;
            newpool.Properties["WAMUserName"].Value = username;
            newpool.Properties["WAMUserPass"].Value = password;
        }
        newpool.CommitChanges();

Attempt 2

        string metabasePath = @"IIS://localhost/W3SVC/AppPools";

        DirectoryEntry apppools = new DirectoryEntry(metabasePath);
        DirectoryEntry newpool = apppools.Children.Add(AppPoolName, "IIsApplicationPool");
        newpool.Properties["managedRuntimeVersion"].Value = "v4.0";
        newpool.Properties["ManagedPipelineMode"][0] = 0; //exception thrown on this line
        newpool.Properties["Enable32BitAppOnWin64"].Value = true;
        if (!string.IsNullOrEmpty(username))
        {
            newpool.Properties["AppPoolIdentityType"].Value = 3;
            newpool.Properties["WAMUserName"].Value = username;
            newpool.Properties["WAMUserPass"].Value = password;
        }
        newpool.CommitChanges();

The same exception is thrown either way.

Exception:

Exception from HRESULT: 0x80005006
    at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.PutEx(Int32 lnControlCode, String bstrName, Object vProp)
    at System.DirectoryServices.PropertyValueCollection.OnClearComplete()
    at System.DirectoryServices.PropertyValueCollection.set_Value(Object value)
Was it helpful?

Solution

Turns out my issue was a bit more fundamental than I thought. First of all, IIS 6 doesn't support integrated pipeline mode, so the switch ManagedPipelineMode doesn't even exist. Also, the Enable32BitAppOnWin64 doesn't exist in this fashion either, to turn that feature on, a command has to be run (https://web.archive.org/web/20160313115849/http://extended64.com/blogs/rhoffman/archive/2005/05/10/482.aspx)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top