c# - IIS 7 配置数据库 : Setting the framework version and the managed pipeline mode programmatically

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

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

最佳答案

您可以使用 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();
}

关于c# - IIS 7 配置数据库 : Setting the framework version and the managed pipeline mode programmatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3967906/

相关文章:

javascript - 尝试使用 WebView 上的 JavaScript 按钮调用 C# 代码

c# - 如何让 silverlight 从 MySQL 获取数据

c# - 为什么 List<> 实现 IList

asp.net-mvc - 如何保护 asp.net MVC 中的目录?

c# - SOLID , SRP , I可比

Java保留对象的实例并保留对象的索引

c# - 如何在 C# 中读取 MKV 电影文件的长度和其他信息?

javascript - JQuery 'thinks' 我想要 AJAX 另一个域

iis - appcmd.exe 添加/更改网站子目录的 MIME 类型

c# - 在Microsoft Silverlight中实现可滚动 map (如Google Maps)的最佳方法是什么?