Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does ServerManager finds the states of an given site

I am trying to read the status of a site using Servermanager. Basically this is what I have,

var serverManager = new ServerManager(siteInstance.Server.ConfigPath);
    var site = serverManager.Sites.FirstOrDefault(x => x.Id == Convert.ToInt64(siteInstance.IisIdentifier));
    return site.State.ToString();

I am able to read the config file and site details without any issue. But the status of the site is either giving me COM error below or giving an status that doesn't reflect the actual status of the site in IIS.

The object identifier does not represent a valid object. (Exception from HRESULT: 0x800710D8)

To my understanding, config file only contains the site information. It doesn't indicate which IIS servers are reading from the config. So how does the ServerManager know which IIS to look into to look for the running status of the site?

like image 436
jack Avatar asked Nov 20 '25 22:11

jack


1 Answers

The reason you are getting the site is because you are trying to read the status from site configuration file, which doesn't contain the state of the site. Instead, what you should be doing is connect directly to IIS server like this:

ServerManager manager= ServerManager.OpenRemote("testserver");
var site = manager.Sites.First();
var status = site.State.ToString() ;

Please refer to my post below for full details: Programmatically get site status from IIS, gets back COM error

like image 161
Jack Avatar answered Nov 22 '25 10:11

Jack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!