Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# IIS 7元数据库:以编程方式设置框架版本和托管管道模式_C#_.net_Iis_Iis 7_Iis Metabase - Fatal编程技术网

C# IIS 7元数据库:以编程方式设置框架版本和托管管道模式

C# IIS 7元数据库:以编程方式设置框架版本和托管管道模式,c#,.net,iis,iis-7,iis-metabase,C#,.net,Iis,Iis 7,Iis Metabase,如何通过C#以编程方式为IIS 7设置ehe.net framework版本和托管管道模式?该程序集的元数据库属性名称是什么?您可以使用该程序集。以下是设置框架版本的方法: using (var manager = new ServerManager()) { // Get the web site given its unique id var site = manager.Sites.Cast<Site>().Where(s => s.Id == 1).Fi

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

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

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();
}

谢谢你的回答。但由于某些原因,我无法使用Microsoft.Web.Administration。我必须用DirectoryEntry来做,我是在Windows XP下开发的,但是这个软件是在Windows 2008服务器上运行的。然而,我已经为自己找到了解决办法。
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();
}