AppPool Invoke returns Unknown name. Exception (DISP_E_UNKNOWNNAME)

2

When using Directory services in IIS7, I am unable to get the invoke(method) to work with the app pool. It consistently returns the unknown name exception. Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))

I am able to use the InvokeGet command to get property data from the app pool, but invoke consistently fails. It's as if the method names were changed between IIS6 and IIS7.

The code is run by a web page running on an Windows 2003 box with IIS6, It is querying a Windows 2008 box with IIS7.5

Here is my code:

        string machineName = this.MYMACH.Text; 
        string query;
        string Usrnm = GetUSRNAME();  //decrypts admin user name
        string Pswd = GetPSWORD();    //decrypts admin user password
        query = String.Format("IIS://{0}/w3svc/AppPools/{1}", machineName, AppPoolName);
        DirectoryEntry w3svc = new DirectoryEntry(query, Usrnm, Pswd);

        try
        {
            if (4 == (int)w3svc.InvokeGet("AppPoolState"))   //   <--- works
            {
                w3svc.Invoke("Start", null);
                errormsgs.Text = string.Format("Application pool {0} retarted", btn.Text);
            }
            else
            {
                w3svc.Invoke("Recycle", null);      <--- Excepts
                errormsgs.Text = string.Format("Application pool {0} recycled", btn.Text);
            }

        }
        catch (Exception eee)
        {
            errormsgs.Text = string.Format("Application pool {0} recycle error {1}... Query text = {2}", btn.Text, eee.Message, query);
        }

I've tried the invoke several ways: w3svc.Invoke("Recycle", null); w3svc.Invoke("Recycle", object[]{}); w3svc.Invoke("Recycle");

None of them work

any ideas?

iis-7.5
invoke
application-pool
asked on Stack Overflow Sep 7, 2011 by Jeffg

1 Answer

2

This is because your code doesn't have the right to use local DCOM to do the invoke. Try :

<system.web>
    <identity impersonate="true" userName="" password="" />
</system.web>

Make sure you use a local domain account have the right to use DCOM on this machine.

Also, you can change the local DCOM setting to give your local app pool user rights.

answered on Stack Overflow Oct 16, 2012 by Licheng • edited Oct 16, 2012 by rolve

User contributions licensed under CC BY-SA 3.0