Recycle External Pools in C#

-6

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?

c#
server
asked on Stack Overflow Oct 5, 2018 by Ricardo Müller • edited Oct 5, 2018 by Ricardo Müller

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0