Home
> Uncategorized > Start an IIS website synchronously with ADSI
Start an IIS website synchronously with ADSI
Using ADSI, once you have a DirectoryEntry object for a given website using
var root = new DirectoryEntry(“IIS://localhost/W3SVC”);
foreach (DirectoryEntry e in root.Children)
{
if (e.SchemaClassName != “IIsWebServer”) continue;// e now represents a website in IIS
}
You can start and stop it using
Entry.Invoke(“start”);
Entry.Invoke(“stop”);
However, these commands run asynchronously, and you need to poll on the value
Entry.Invoke(“Get”, “ServerState”)
Where 4 is stopped and 2 is started. However, those using IISAdmin.net will find that this value never changes, meaning that it is impossible to tell when the website has actually changed state. Therefore, my fix was calling:
Entry.RefreshCache();
Prior to calling Invoke/Get
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback