Recycle external pools in C #

0

I'm trying to recycle pools on external IIS servers from a C # code. 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 "0x80005000 - Unknown Error."

As another try, I tried using the Server Manager and Application Pool methods.

ServerManager serverManager = new ServerManager(ipServidor);
ApplicationPool appPool = serverManager.ApplicationPools[NomePool];
        if (appPool != null)
        {
            if (appPool.State == ObjectState.Stopped){
                appPool.Start();
            }else{
                appPool.Recycle();
            }
        }

But the serverManager can not instantiate and consequently does not have ApplicationPools.

Any suggestions?

    
asked by anonymous 05.10.2018 / 18:45

0 answers