如何使用Microsoft.Web.Administration.dll获得页面上运行的网站的信息? [英] How to use Microsoft.Web.Administration.dll to get the site information the page is running on?

查看:696
本文介绍了如何使用Microsoft.Web.Administration.dll获得页面上运行的网站的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的服务器上半打的网站,我想从IIS7得到一些信息,在每个页面的页脚显示(只要你当然是管理员)。我经历的ServerObject,发现站点,但我没有找到任何明显的此站点。 我应该怎么做,该网页上运行的信息在IIS7的确切部位得到什么?

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?

对于一个快速'黑客'式的方法我写了这背后我的Default.aspx页面code:

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

推荐答案

如果你是后获取有关当前网站上的一些简单的信息,也有一些伟大的方法,如 HostingEnvironment.ApplicationHost.GetSiteName( ) HostingEnvironment.ApplicationHost.GetSiteID()等。否则,下面的code段可能会有所帮助。

If you are after to get some simple information about the current website, there are some great methods such as HostingEnvironment.ApplicationHost.GetSiteName() or HostingEnvironment.ApplicationHost.GetSiteID() and so on. Otherwise, the following code snippet may be helps.

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

这篇关于如何使用Microsoft.Web.Administration.dll获得页面上运行的网站的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆