IIS 7配置数据库:以编程方式设置框架版本和托管管道模式 [英] IIS 7 metabase: Setting the framework version and the managed pipeline mode programmatically
本文介绍了IIS 7配置数据库:以编程方式设置框架版本和托管管道模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过C#以编程方式为IIS 7程序设置 .net框架版本和托管管道模式?元数据库属性的名称是什么?
How can I set the ehe .net framework version and the managed pipeline mode programmatically for a IIS 7 programmatic via C#? What a the metabase property names for that?
推荐答案
您可以使用 Microsoft.Web.Administration 程序集。以下是如何设置框架版本:
You could use the Microsoft.Web.Administration assembly. Here's how you could set the framework version:
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();
}
以下是如何将托管管道模式设置为集成:
And here's how to set the managed pipeline mode to integrated:
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();
}
这篇关于IIS 7配置数据库:以编程方式设置框架版本和托管管道模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文