IIS 7 Metabase:フレームワークバージョンと管理されたパイプラインモードの設定プログラム

StackOverflow https://stackoverflow.com/questions/3967906

質問

eheを設定するにはどうすればよいですか .NETフレームワークバージョン そしてその 管理されたパイプラインモード C#を介したIIS 7プログラマティックのプログラムで?そのためのMetabaseプロパティ名は何ですか?

役に立ちましたか?

解決

使用できます 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();
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top