iis 80端口 默认导航首页

直接iis 80端口 默认导航首页 ,

可以不用再记住你每个开发网站的端口了.

自动显示你的iis当前有多少站点

.点击链接就可以直达

这个程序是从我老大那里拿来的.

非常好用

using System;
using System.Collections.Generic;
using System.DirectoryServices;

public partial class _default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int TotalServerCount = 0;
        DirectoryEntry rootfolder = new DirectoryEntry("IIS://localhost/W3SVC");

        foreach (DirectoryEntry child in rootfolder.Children)
        {
            if (child.SchemaClassName == "IIsWebServer")
            {
                TotalServerCount += 1;
            }
        }

        //循环获取所有站点详细属性写入数组中
        Dictionary<int, string> sites = new Dictionary<int, string>();
        Dictionary<int, string> paths = new Dictionary<int, string>();
        int[] arrayServerPort = new int[TotalServerCount];

        string currentServerBindings;//绑定主机头IP端口字符串
        char[] a = ":".ToCharArray();
        string[] currentBingdings = new string[2];

        int i = 0;
        foreach (DirectoryEntry child in rootfolder.Children)
        {
            if (child.SchemaClassName == "IIsWebServer")
            {
                currentServerBindings = child.Properties["ServerBindings"].Value.ToString();
                currentBingdings = currentServerBindings.Split(a);

                sites.Add(int.Parse(currentBingdings[1]), child.Properties["ServerComment"].Value.ToString());

                foreach (DirectoryEntry rootChild in child.Children)
                {
                    if (rootChild.Name.ToString().ToLower() == "root")
                    {
                        if (rootChild.Properties["Path"].Value == null)
                        {
                            paths.Add(int.Parse(currentBingdings[1]), "");
                        }
                        else
                        {
                            paths.Add(int.Parse(currentBingdings[1]), rootChild.Properties["Path"].Value.ToString());
                        }
                    }
                }

                arrayServerPort.SetValue(int.Parse(currentBingdings[1]), i);

                i += 1;
            }
        }

        Reorder(ref arrayServerPort);

        //输出站点信息
        for (i = 0; i < TotalServerCount; i++)
        {
            Response.Write("<span style=\"width:280px;display:block;float:left;\"><a href=\"http://localhost:" + arrayServerPort[i].ToString() + "\">站点名称: " + sites[arrayServerPort[i]] + "</a></span>");
            Response.Write("<span style=\"width:80px;display:block;float:left;\">端口: " + arrayServerPort[i].ToString() + "</span>");
            Response.Write("<span style=\"display:block;float:left;\">路径: " + paths[arrayServerPort[i]] + "</span>"); 
            Response.Write("<br>");
        }
    }

    private void Reorder(ref int[] args)
    {
        int j, temp;
        for (int i = 0; i < args.Length - 1; i++)
        {
            j = i + 1;
        aa:
            if (args[i] > args[j])
            {
                temp = args[i];
                args[i] = args[j];
                args[j] = temp;
                goto aa;
            }
            else
                if (j < args.Length - 1)
                {
                    j++;
                    goto aa;
                }
        }
    }
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值