From 345f79c73778bc35670f710e05567899dd8a500d Mon Sep 17 00:00:00 2001 From: Doug Morgan Date: Thu, 6 Aug 2015 20:41:15 -0400 Subject: [PATCH] Added Ability to specify Identity for AppPool --- src/app/Fake.IIS/IISHelper.fs | 35 ++++++++++++++++++++++------------- src/app/Fake.IIS/Script.fsx | 12 ++++++++---- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/app/Fake.IIS/IISHelper.fs b/src/app/Fake.IIS/IISHelper.fs index 1bf1c00f530..518e7c9a51d 100644 --- a/src/app/Fake.IIS/IISHelper.fs +++ b/src/app/Fake.IIS/IISHelper.fs @@ -51,19 +51,6 @@ let Site (name : string) protocol binding (physicalPath : string) appPool (mgr : site.ApplicationDefaults.ApplicationPoolName <- appPool site -let ApplicationPool (name : string) (allow32on64:bool) (runtime:string) (mgr : ServerManager) = - let appPool = mgr.ApplicationPools.[name] - match (appPool) with - | null -> - let pool = mgr.ApplicationPools.Add(name) - pool.Enable32BitAppOnWin64 <- allow32on64 - pool.ManagedRuntimeVersion <- runtime - pool - | _ -> - appPool.Enable32BitAppOnWin64 <- allow32on64 - appPool.ManagedRuntimeVersion <- runtime - appPool - let Application (virtualPath : string) (physicalPath : string) (site : Site) (mgr : ServerManager) = let app = site.Applications.[virtualPath] match (app) with @@ -72,6 +59,28 @@ let Application (virtualPath : string) (physicalPath : string) (site : Site) (mg let commit (mgr : ServerManager) = mgr.CommitChanges() +type ApplicationPoolConfig(name : string, ?runtime:string, ?allow32on64:bool, ?identity : ProcessModelIdentityType) = class + member this.name = name + member this.runtime = defaultArg runtime "v4.0" + member this.allow32on64 = defaultArg allow32on64 false + member this.identity = defaultArg identity ProcessModelIdentityType.ApplicationPoolIdentity +end + +let private MergeAppPoolProperties (appPool:ApplicationPool)(config:ApplicationPoolConfig) = + appPool.Enable32BitAppOnWin64 <- config.allow32on64 + appPool.ManagedRuntimeVersion <- config.runtime + appPool.ProcessModel.IdentityType <- config.identity + appPool + +let ApplicationPool (config: ApplicationPoolConfig) (mgr : ServerManager) = + let appPool = mgr.ApplicationPools.[config.name] + match (appPool) with + | null -> + let pool = mgr.ApplicationPools.Add(config.name) + MergeAppPoolProperties pool config + | _ -> + MergeAppPoolProperties appPool config + let IIS (site : ServerManager -> Site) (appPool : ServerManager -> ApplicationPool) (app : (Site -> ServerManager -> Application) option) = diff --git a/src/app/Fake.IIS/Script.fsx b/src/app/Fake.IIS/Script.fsx index ef9e653b090..dc00ab70394 100644 --- a/src/app/Fake.IIS/Script.fsx +++ b/src/app/Fake.IIS/Script.fsx @@ -1,8 +1,9 @@ -#r @"..\..\..\packages\Microsoft.Web.Administration.7.0.0.0\lib\net20\Microsoft.Web.Administration.dll" +#r @"..\..\..\packages\Microsoft.Web.Administration\lib\net20\Microsoft.Web.Administration.dll" #r @"..\..\..\build\FakeLib.dll" #load "IISHelper.fs" open Fake.IISHelper +open Microsoft.Web let siteName = "fake.site" let appPool = "fake.appPool" @@ -12,15 +13,18 @@ let appDir = @"C:\Users" UnlockSection "system.webServer/security/authentication/anonymousauthentication" +let dotNetFourAppPool = ApplicationPoolConfig(siteName, allow32on64 = true, identity = Administration.ProcessModelIdentityType.LocalSystem) +let dotNetTwoAppPool = ApplicationPoolConfig(siteName, runtime = "v2.0", allow32on64 = true) + (IIS (Site siteName "http" port @"C:\inetpub\wwwroot" appPool) - (ApplicationPool appPool true "v4.0") + (ApplicationPool dotNetFourAppPool) (Some(Application vdir appDir))) (IIS (Site siteName "http" port @"C:\inetpub\wwwroot" appPool) - (ApplicationPool appPool true "v2.0") + (ApplicationPool dotNetTwoAppPool) (Some(Application "/vdir2" @"C:\temp"))) deleteSite siteName -deleteApplicationPool appPool +deleteApplicationPool appPool \ No newline at end of file