I am trying to recycle pools on external IIS servers from a code in C #. After a search I found this method
string username = "user";
string password = "password";
string path = "IIS://ipServidor/nomeServidor/AppPools/NomePool";
using (DirectoryEntry appPoolEntry = new DirectoryEntry(path, username, password)){
try{
appPoolEntry.Invoke("Recycle", null);
}catch (Exception ex){
var e = ex;
}
}
As an exception I get the return "0x80005000 - Unknown Error"
As another attempt, I tried using the methods of * Server Manager * and * Application Pool *
ServerManager serverManager = new ServerManager(ipServidor);
ApplicationPool appPool = serverManager.ApplicationPools[NomePool];
if (appPool != null)
{
if (appPool.State == ObjectState.Stopped){
appPool.Start();
}else{
appPool.Recycle();
}
}
Any suggestion?
User contributions licensed under CC BY-SA 3.0