How to use Microsoft.Web.Administration.dll to get information about the site the page is running on?

I have half a dozen sites on my server, and I would like to get some information from IIS7 to display in the footer of each page (while you, of course, are the administrator). I look through ServerObject and find sites, but have not found anything obvious for "this site". What should I do to get information for the exact site in IIS7 the page is running on?

For a quick “crack” style approach, I wrote this on my default.aspx file 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

+3
source share
1 answer

-, , HostingEnvironment.ApplicationHost.GetSiteName() HostingEnvironment.ApplicationHost.GetSiteID() .. .

using (ServerManager sm = new ServerManager())
{
    foreach (Binding b in sm.Sites[HostingEnvironment.ApplicationHost.GetSiteName()].Bindings)
    {
        // ...
    }
}
+3

Source: https://habr.com/ru/post/1749678/


All Articles