AppPool Invoke returns Unknown name. Exception (DISP_E_UNKNOWNNAME)
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?
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.
精彩评论