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

C#中操作IIS 7.0

 2009-03-25 08:20:35 来源:WEB开发网   
核心提示: 删除应用程序池,DeletePool /// <summary> /// Delete an existent web site app pool. /// </summary> /// <param name="appPoolName"

删除应用程序池。

DeletePool

/// <summary>
/// Delete an existent web site app pool.
/// </summary>
/// <param name="appPoolName">App pool name for deletion.</param>
public static void DeletePool(string appPoolName)
{
    using (ServerManager mgr = new ServerManager())
    {
        ApplicationPool pool = mgr.ApplicationPools[appPoolName];
        if (pool != null)
        {
            mgr.ApplicationPools.Remove(pool);
            mgr.CommitChanges();
        }
    }
}

在站点上添加默认文档。

AddDefaultDocument public static void AddDefaultDocument(string siteName, string defaultDocName)
{
    using (ServerManager mgr = new ServerManager())
    {
        Configuration cfg = mgr.GetWebConfiguration(siteName);
        ConfigurationSection defaultDocumentSection = cfg.GetSection("system.webServer/defaultDocument");
        ConfigurationElement filesElement = defaultDocumentSection.GetChildElement("files");
        ConfigurationElementCollection filesCollection = filesElement.GetCollection();

        foreach (ConfigurationElement elt in filesCollection)
        {
            if (elt.Attributes["value"].Value.ToString() == defaultDocName)
            {
                return;
            }
        }

        try
        {
            ConfigurationElement docElement = filesCollection.CreateElement();
            docElement.SetAttributeValue("value", defaultDocName);
            filesCollection.Add(docElement);
        }
        catch (Exception) { }   //this will fail if existing

        mgr.CommitChanges();
    }
}

上一页  1 2 3 4  下一页

Tags:操作 IIS

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