发布一个小工具:建立站点和域名绑定(附代码)

     当我们在网上下载开源的WEB程序时,有好些程序不能在虚拟目录下运行. 为了让程序运行起来,我们要建Website ,然后设一个主机头,再去修改host文件.写次去找那个目录结构好深的文件感觉到好麻烦,所以写下这个小工具.
    小工具用到的主要技术就是对IIS进行操作,网上已经有许多代码,但是都不够完整. 另外程序还将自动的修改你的HOST文件. 在绑定IP的时候格式为 IP:PORT:DOMAIN
    创建的程序如下:难点在于如何去找,Properties中所对应的KEY,对于PATH这个KEY;居然是在children下面创建.MS的这种设计模式不知道有什么好处.

string  entPath  =  String.Format( " IIS://{0}/w3svc " , HostName);
            DirectoryEntry rootEntry 
=  GetDirectoryEntry(entPath); // 取得iis路径
             string  newSiteNum  =  GetNewWebSiteID();  // 取得新网站ID
            DirectoryEntry newSiteEntry  =  rootEntry.Children.Add(newSiteNum,  " IIsWebServer " );  // 增加站点
            newSiteEntry.CommitChanges(); // 保存对区域的更改(这里对站点的更改)
            newSiteEntry.Properties[ " ServerBindings " ].Value  =  domainIP;
            newSiteEntry.Properties[
" ServerComment " ].Value  =  commentOfWebSite;
            newSiteEntry.Properties[
" AccessRead " ][ 0 =   true ;
            newSiteEntry.Properties[
" AccessExecute " ][ 0 =   true ;
            newSiteEntry.Properties[
" AppPoolId " ][ 0 =   " DefaultAppPool " ;

                 
            
// newSiteEntry.Properties["AccessWrite"][0] = true;
            newSiteEntry.CommitChanges();
            DirectoryEntry vdEntry 
=  newSiteEntry.Children.Add( " root " " IIsWebVirtualDir " );
            vdEntry.CommitChanges();
            vdEntry.Properties[
" Path " ].Value  =  webPath;
            vdEntry.CommitChanges();

            vdEntry.Invoke(
" AppCreate " 1 );

整个程序比较简单,有兴趣的下载代码.  程序下载

转载于:https://www.cnblogs.com/mediar/archive/2008/05/18/1201760.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值