【问题标题】:IIS 7 metabase: Setting the framework version and the managed pipeline mode programmaticallyIIS 7 元数据库:以编程方式设置框架版本和托管管道模式
【发布时间】:2010-10-19 11:39:31
【问题描述】:

如何通过 C# 为 IIS 7 编程设置 ehe .net 框架版本 和 托管管道模式?什么是元数据库属性名称?

【问题讨论】:

    标签: c# .net iis iis-7 iis-metabase


    【解决方案1】:

    您可以使用Microsoft.Web.Administration 程序集。以下是设置框架版本的方法:

    using (var manager = new ServerManager())
    {
        // Get the web site given its unique id
        var site = manager.Sites.Cast<Site>().Where(s => s.Id == 1).FirstOrDefault();
        if (site == null)
        {
            throw new Exception("The site with ID = 1 doesn't exist");
        }
    
        // get the application you want to set the framework version to
        var application = site.Applications["/vDirName"];
        if (application == null)
        {
            throw new Exception("The virtual directory /vDirName doesn't exist");
        }
    
        // get the corresponding application pool
        var applicationPool = manager.ApplicationPools
            .Cast<Microsoft.Web.Administration.ApplicationPool>()
            .Where(appPool => appPool.Name == application.ApplicationPoolName)
            .FirstOrDefault();
        if (applicationPool == null)
        {
            // normally this should never happen
            throw new Exception("The virtual directory /vDirName doesn't have an associated application pool");
        }
    
        applicationPool.ManagedRuntimeVersion = "v4.0.30319";
        manager.CommitChanges();
    }
    

    以下是如何将托管管道模式设置为集成:

    using (var manager = new ServerManager())
    {
        // Get the application pool given its name
        var appPool = manager.ApplicationPools["AppPoolName"];
        if (appPool == null)
        {
            throw new Exception("The application pool AppPoolName doesn't exist");
        }
    
        // set the managed pipeline mode
        appPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
    
        // save
        manager.CommitChanges();
    }
    

    【讨论】:

    • 感谢您的回答。但由于某些原因,我无法使用 Microsoft.Web.Administration。我必须使用 DirectoryEntry
    • 我在 Windows XP 下开发,但软件在 Windows 2008 服务器上运行。不过,我已经为自己找到了解决方案。
    猜你喜欢
    • 2013-07-18
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 2019-02-07
    • 1970-01-01
    • 2010-12-10
    • 2013-05-31
    相关资源
    最近更新 更多