Hello,
I was successful in getting this code to work, which will tap IIS to get my webrole site application pool status for each site ... just so I can quickly toss the information into a webpage. BTW: Yes, I do understand that this is only going to hit
IIS on the server where this instance is running. I'm just messing around getting info out of Azure without having to use log files and polling and parsing data out of log files. I was just looking for a quick and easy way to get app status tossed into a webpage.
I speculate that another way would be to use the Service Management API endpoints and check the apps are running by interacting directly with their endpoints ... VIP targeting of each instance endpoint perhaps? Anyhow ... here is what I was playing with:
Using serverManager As New Microsoft.Web.Administration.ServerManager
Dim sb As New StringBuilder
Dim appSiteCollection As SiteCollection = serverManager.Sites()
For Each app As Site In appSiteCollection
sb.Append(app.Name & ": " & app.State.ToString & vbCrLf)
Next
Me.TextBox_Output.Text = sb.ToString
End Using
I had to add references to:
System.DirectoryServices
Microsoft.Web.Administration (found at: C:\Windows\System32\inetserv)
and running in ServiceDefinition.csdef:
<Runtime executionContext="elevated" />
However, I also had to impersonate my Azure Admin account in Web.config to avoid a nasty access permission exception:
<identity impersonate="true" userName="<MyAzureUserName>" password="<MyAzurePassword>" />
Question: How can I make this work without having to impersonate? I DON'T want to leave my credientials in the Web.config file like this. Can I connect to the webrole instances and set permissions manually for NETWORK SERVICE to access IIS?
That might not survive webrole restart/reboots, but it would be a lot better than exposing my admin account like this.