I have a half dozen sites on my server and I would like to get some info from IIS7 to display in the footer of each page (as long as you are an admin of course). I am going through the ServerObject and found Sites but am not finding anything obvious for “this site”. What should I do to get at the information for the exact site in IIS7 that the page is running on?
For a quick ‘hack’ style approach I wrote this on my default.aspx page code behind:
ServerManager serverMgr = new ServerManager();
foreach (Site site in serverMgr.Sites)
{
string s = info.Text + site.Name + @"<br/>";
info.Text = s;
foreach (Binding binding in site.Bindings)
{
string t = info.Text + binding.BindingInformation + " | ";
string p = t + binding.Protocol + @"<br/>";
info.Text = p;
}
}
TIA
If you are after to get some simple information about the current website, there are some great methods such as
HostingEnvironment.ApplicationHost.GetSiteName()orHostingEnvironment.ApplicationHost.GetSiteID()and so on. Otherwise, the following code snippet may be helps.