ASP.Net管理IIS7

老程序是管理IIS6,服务器更新IIS7后不能使用。

在网上查询到这个地址的介绍http://dflying.cnblogs.com/archive/2006/04/17/377276.html

不过按照上面的代码不能生成。

ServerManager iisManager  =   new  ServerManager();
iisManager.Sites.Add(
" NewSite " " http " " *:8080: " " d:\\MySite " );
iisManager.Update(); 

 

显示没有 Update方法。

 

经过查询MSDN,找到解决办法,调试成功。

 

         ///   <summary>
        
///  IIS7创建网站
        
///   </summary>
        
///   <param name="name"> 网站名称 </param>
        
///   <param name="Port"> 端口 </param>
        
///   <param name="domain"> 绑定域名 </param>
         public   void  CreateSiteByName( string  name,  string  Port,  string  domain)
        {
            
string  path  =   @" C:\web\ "   +  name  +   " site " ;

            
//  Validate the site name
             char [] invalid  =  SiteCollection.InvalidSiteNameCharacters();
            
if  (name.IndexOfAny(invalid)  >   - 1 )
            {
                Console.WriteLine(
" Invalid site name: {0} " , name);
            }

            
//  Create the content directory if it doesn't exist.
             if  ( ! System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }

            
//  Create a new site using the new directory and update the config
            ServerManager manager  =   new  ServerManager();
            
try
            {   
//  Add this site.

                Site hrSite 
=  manager.Sites.Add(name,  " http " " *: "   +  Port  +   " : "   +  domain, path);
                hrSite.ServerAutoStart 
=   true ;
                manager.CommitChanges();
                Console.WriteLine(
" Site  "   +  name  +   "  added to ApplicationHost.config file. " );
            }
            
catch
            {
            }
        }

 

 

 

 程序发布的时候显示有没权限。需要给C:\Windows\System32\inetsrv\config添加network service用户权限才行。 

转载于:https://www.cnblogs.com/dpol/archive/2009/12/08/1619486.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值