CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

如何实现下列功能?

楼主f_h_x_(不要问我)2004-12-01 17:33:54 在 .NET技术 / C# 提问

C#如何操作IIS?如何用代码建虚拟目录?  
   
  在线等>分不够再加. 问题点数:100、回复次数:4Top

1 楼nga96(因为我笨,所以努力。陈勇华)回复于 2004-12-01 17:50:41 得分 0

分太少了些吧,呵  
  代码我有,不知如何给你呢Top

2 楼shenyisyn(魔法师)回复于 2004-12-01 17:51:12 得分 20

public   static   DirectoryEntry   GetDirectoryEntry(string   entPath)  
   
                    {  
   
                              DirectoryEntry   ent;  
   
     
   
                              if(UserName   ==   null)  
   
                              {  
   
                                        ent   =   new   DirectoryEntry(entPath);  
   
                              }  
   
                              else  
   
                              {  
   
                                        //         ent   =   new   DirectoryEntry(entPath,   HostName+"\\"+UserName,   Password,   AuthenticationTypes.Secure);  
   
                                        ent   =   new   DirectoryEntry(entPath,   UserName,   Password,   AuthenticationTypes.Secure);  
   
                              }  
   
     
   
                              return   ent;  
   
                    }  
   
      #region   添加,删除网站的方法  
   
                    ///   <summary>  
   
                    ///     创建一个新的网站。根据传过来的信息进行配置  
   
                    ///   </summary>  
   
                    ///   <param   name="siteInfo">存储的是新网站的信息</param>  
   
                    public   static   void   CreateNewWebSite(NewWebSiteInfo   siteInfo)  
   
                    {  
   
                              if(!   EnsureNewSiteEnavaible(siteInfo.BindString))  
   
                              {  
   
                                        throw   new   DuplicatedWebSiteException("已经有了这样的网站了。"   +   Environment.NewLine   +   siteInfo.BindString);  
   
                              }  
   
     
   
                              string   entPath   =   String.Format("IIS://{0}/w3svc",   HostName);  
   
                              DirectoryEntry   rootEntry   =   GetDirectoryEntry(entPath);  
   
     
   
                              string   newSiteNum   =   GetNewWebSiteID();  
   
                              DirectoryEntry   newSiteEntry   =   rootEntry.Children.Add(newSiteNum,   "IIsWebServer");  
   
                              newSiteEntry.CommitChanges();  
   
     
   
                              newSiteEntry.Properties["ServerBindings"].Value   =   siteInfo.BindString;  
   
                              newSiteEntry.Properties["ServerComment"].Value   =   siteInfo.CommentOfWebSite;  
   
                              newSiteEntry.CommitChanges();  
   
     
   
                              DirectoryEntry   vdEntry   =   newSiteEntry.Children.Add("root",   "IIsWebVirtualDir");  
   
                              vdEntry.CommitChanges();  
   
     
   
                              vdEntry.Properties["Path"].Value   =   siteInfo.WebPath;  
   
                              vdEntry.CommitChanges();  
   
                    }  
   
  Top

3 楼shenyisyn(魔法师)回复于 2004-12-01 17:51:41 得分 30

///   <summary>  
   
                    ///     删除一个网站。根据网站名称删除。  
   
                    ///   </summary>  
   
                    ///   <param   name="siteName">网站名称</param>  
   
                    public   static   void   DeleteWebSiteByName(string   siteName)  
   
                    {  
   
                              string   siteNum   =   GetWebSiteNum(siteName);  
   
                              string   siteEntPath   =   String.Format("IIS://{0}/w3svc/{1}",   HostName,   siteNum);  
   
                              DirectoryEntry   siteEntry   =   GetDirectoryEntry(siteEntPath);  
   
     
   
                              string   rootPath   =   String.Format("IIS://{0}/w3svc",   HostName);  
   
                              DirectoryEntry   rootEntry   =   GetDirectoryEntry(rootPath);  
   
     
   
                              rootEntry.Children.Remove(siteEntry);  
   
                              rootEntry.CommitChanges();  
   
                    }  
   
                      #endregion  
   
     
   
                      #region   Start和Stop网站的方法  
   
                    public   static   void   StartWebSite(string   siteName)  
   
                    {  
   
                              string   siteNum   =   GetWebSiteNum(siteName);  
   
                              string   siteEntPath   =   String.Format("IIS://{0}/w3svc/{1}",   HostName,   siteNum);  
   
                              DirectoryEntry   siteEntry   =   GetDirectoryEntry(siteEntPath);  
   
     
   
                              siteEntry.Invoke("Start",   new   object[]   {});  
   
                    }  
   
     
   
                    public   static   void   StopWebSite(string   siteName)  
   
                    {  
   
                              string   siteNum   =   GetWebSiteNum(siteName);  
   
                              string   siteEntPath   =   String.Format("IIS://{0}/w3svc/{1}",   HostName,   siteNum);  
   
                              DirectoryEntry   siteEntry   =   GetDirectoryEntry(siteEntPath);  
   
     
   
                              siteEnt  
  Top

4 楼shenyisyn(魔法师)回复于 2004-12-01 17:52:06 得分 50

public   static   bool   EnsureNewSiteEnavaible(string   bindStr)  
   
                    {  
   
                              string   entPath   =   String.Format("IIS://{0}/w3svc",   HostName);  
   
                              DirectoryEntry   ent   =   GetDirectoryEntry(entPath);  
   
         
   
                              foreach(DirectoryEntry   child   in   ent.Children)  
   
                              {  
   
                                        if(child.SchemaClassName   ==   "IIsWebServer")  
   
                                        {  
   
                                                  if(child.Properties["ServerBindings"].Value   !=   null)  
   
                                                {  
   
                                                          if(child.Properties["ServerBindings"].Value.ToString()   ==   bindStr)  
   
                                                          {  
   
                                                                    return   false;  
   
                                                          }  
   
                                                }  
   
                                        }  
   
                              }  
   
     
   
                              return   true;  
   
                    }  
   
                      #endregion  
   
     
   
                      #region   获取一个网站编号的方法  
   
                    ///   <summary>  
   
                    ///     获取一个网站的编号。根据网站的ServerBindings或者ServerComment来确定网站编号  
   
                    ///   </summary>  
   
                    ///   <param   name="siteName"></param>  
   
                    ///   <returns>返回网站的编号</returns>  
   
                    ///   <exception   cref="NotFoundWebSiteException">表示没有找到网站</exception>  
   
                    public   static   string   GetWebSiteNum(string   siteName)  
   
                    {  
   
                              Regex   regex   =   new   Regex(siteName);  
   
                              string   tmpStr;  
   
     
   
                              string   entPath   =   String.Format("IIS://{0}/w3svc",   HostName);  
   
                              DirectoryEntry   ent   =   GetDirectoryEntry(entPath);  
   
         
   
                              foreach(DirectoryEntry   child   in   ent.Children)  
   
                              {  
   
                                        if(child.SchemaClassName   ==   "IIsWebServer")  
   
                                        {  
   
                                                  if(child.Properties["ServerBindings"].Value   !=   null)  
   
                                                {  
   
                                                          tmpStr   =   child.Properties["ServerBindings"].Value.ToString();  
   
                                                          if(regex.Match(tmpStr).Success)  
   
                                                          {  
   
                                                                    return   child.Name;  
   
                                                          }  
   
                                                }  
   
     
   
                                                  if(child.Properties["ServerComment"].Value   !=   null)  
   
                                                {  
   
                                                          tmpStr   =   child.Properties["ServerComment"].Value.ToString();  
   
                                                          if(regex.Match(tmpStr).Success)  
   
                                                          {  
   
                                                                    return   child.Name;  
   
                                                          }  
   
                                                }  
   
                                        }  
   
                              }  
   
     
   
                              throw   new   NotFoundWebSiteException("没有找到我们想要的站点"   +   siteName);  
   
                    }  
   
                      #endregion  
   
  Top

相关问题

  • 下列功能如何实现?谢谢!!!
  • 如何实现下列功能?
  • 如何用SQL语句实现下列功能
  • 在微软的DrawCli例子中如何实现下列功能?
  • 怎样用dbgrid实现下列功能
  • 如何实现下列技巧
  • 如何实现下列查询?
  • 如何实现下列的数据
  • 不知到在JAVA中能否实现下列功能:
  • 我想在消息框中实现下列功能!

关键词

  • 网站
  • iis
  • directoryentry
  • entpath
  • sitename
  • newsiteentry
  • siteinfo
  • getdirectoryentry
  • rootentry
  • siteentpath

得分解答快速导航

  • 帖主:f_h_x_
  • shenyisyn
  • shenyisyn
  • shenyisyn

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo