C# 删除IIS 指定域名解析

发布时间2018/9/11 17:26:10

下载次数 0 次 访问量382 次

免开发-应用中心上线啦,专注提供优质插件源码和产品应用!

using Frameworks.Comm;
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int siteId = IISHelper.GetWebSiteID("localhost", "Default Web Site");
            DirectoryEntry site = new DirectoryEntry("IIS://localhost/W3SVC/" + siteId);
            PropertyValueCollection serverBindings = site.Properties["ServerBindings"];
            string headerStr = string.Format(":{0}:{1}", 80, "ygj.code68.com");
            Console.WriteLine("serverBindings.Count"+ serverBindings.Count);


            for (var i = serverBindings.Count-1; i >= 0; i--)
            {
                if(serverBindings[i].ToString()== headerStr)
                {
                    Console.WriteLine("==="+i);
                    serverBindings.Remove(headerStr);
                    break;
                }
                Console.WriteLine(serverBindings[i].ToString());
            }
            site.CommitChanges();
            Console.ReadKey();

        }
    }
}

网友评论

发表评论

欢迎评论哦!