WEB开发网
开发学院软件开发C语言 C#中操作IIS 7.0 阅读

C#中操作IIS 7.0

 2009-03-25 08:20:35 来源:WEB开发网   
核心提示: 这个是删除站点的方法,比较简单,C#中操作IIS 7.0(2),DeleteSite /// <summary> /// Delete an existent web site. /// </summary> /// <param name="si

这个是删除站点的方法,比较简单。

DeleteSite /// <summary>
/// Delete an existent web site.
/// </summary>
/// <param name="siteName">Site name.</param>
public static void DeleteSite(string siteName)
{
    using (ServerManager mgr = new ServerManager())
    {
        Site site = mgr.Sites[siteName];
        if (site != null)
        {
            mgr.Sites.Remove(site);
            mgr.CommitChanges();
        }
    }
}

然后是对虚拟目录的操作,包括创建和删除虚拟目录,都比较简单。

CreateVDir public static void CreateVDir(string siteName, string vDirName, string physicalPath)
{
    using (ServerManager mgr = new ServerManager())
    {
        Site site = mgr.Sites[siteName];
        if (site == null)
        {
            throw new ApplicationException(String.Format("Web site {0} does not exist", siteName));
        }
        site.Applications.Add("/" + vDirName, physicalPath);
        mgr.CommitChanges();
    }
}

DeleteVDir public static void DeleteVDir(string siteName, string vDirName)
{   
    using (ServerManager mgr = new ServerManager())
    {
        Site site = mgr.Sites[siteName];
        if (site != null)
        {
            Microsoft.Web.Administration.Application app = site.Applications["/" + vDirName];
            if (app != null)
            {
                site.Applications.Remove(app);
                mgr.CommitChanges();
            }
        }
    }
}

上一页  1 2 3 4  下一页

Tags:操作 IIS

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接