2 people like it.

IIS Administration F#

Example of how to use F# to create websites in IIS

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
#r "C:\\git\\bitbucket\\folder-generator\\packages\\Microsoft.Web.Administration.7.0.0.0\\lib\\net20\\Microsoft.Web.Administration.dll"

open System
open Microsoft.Web.Administration
                    
let siteName = "doms-wicked-site"

let name(siteType: string) = 
    String.Format("{0}_{1}", siteName, siteType)
        
let serverManager = new ServerManager()
        
let createSite(siteName: string) = 
    serverManager.Sites.Add(siteName, String.Format(@"C:\Sites\{0}", siteName), 80)

let applicationPool(poolName: string) = 
    let livePool:ApplicationPool = serverManager.ApplicationPools.Add(poolName)
    livePool.Enable32BitAppOnWin64 <- true;
    livePool.ManagedRuntimeVersion <- "v4.0";            
    livePool

let site(siteName: string, poolName: string) = 
    let liveSite:Site = createSite(siteName)
    liveSite.ServerAutoStart <- true
    liveSite.ApplicationDefaults.ApplicationPoolName <- poolName       
    liveSite.TraceFailedRequestsLogging.Enabled <- true;
    liveSite.TraceFailedRequestsLogging.Directory <- String.Format(@"C:\IISLogs\{0}", siteName)

let liveName = name("live")
let livePool = applicationPool(liveName)            
let liveSite = site(liveName, livePool.Name)

let accName = name("acc")
let accPool = applicationPool(accName)            
site(accName, accPool.Name) |> ignore
        
serverManager.CommitChanges()   
namespace System
namespace Microsoft
namespace Microsoft.Web
namespace Microsoft.Web.Administration
val siteName : string

Full name: Script.siteName
val name : siteType:string -> string

Full name: Script.name
val siteType : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
Multiple items
type String =
  new : value:char -> string + 7 overloads
  member Chars : int -> char
  member Clone : unit -> obj
  member CompareTo : value:obj -> int + 1 overload
  member Contains : value:string -> bool
  member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
  member EndsWith : value:string -> bool + 2 overloads
  member Equals : obj:obj -> bool + 2 overloads
  member GetEnumerator : unit -> CharEnumerator
  member GetHashCode : unit -> int
  ...

Full name: System.String

--------------------
String(value: nativeptr<char>) : unit
String(value: nativeptr<sbyte>) : unit
String(value: char []) : unit
String(c: char, count: int) : unit
String(value: nativeptr<char>, startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int) : unit
String(value: char [], startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : unit
String.Format(format: string, [<ParamArray>] args: obj []) : string
String.Format(format: string, arg0: obj) : string
String.Format(provider: IFormatProvider, format: string, [<ParamArray>] args: obj []) : string
String.Format(format: string, arg0: obj, arg1: obj) : string
String.Format(format: string, arg0: obj, arg1: obj, arg2: obj) : string
val serverManager : ServerManager

Full name: Script.serverManager
Multiple items
type ServerManager =
  new : unit -> ServerManager + 2 overloads
  member ApplicationDefaults : ApplicationDefaults
  member ApplicationPoolDefaults : ApplicationPoolDefaults
  member ApplicationPools : ApplicationPoolCollection
  member CommitChanges : unit -> unit
  member Dispose : unit -> unit
  member GetAdministrationConfiguration : unit -> Configuration + 1 overload
  member GetApplicationHostConfiguration : unit -> Configuration
  member GetMetadata : metadataType:string -> obj
  member GetRedirectionConfiguration : unit -> Configuration
  ...

Full name: Microsoft.Web.Administration.ServerManager

--------------------
ServerManager() : unit
ServerManager(applicationHostConfigurationPath: string) : unit
ServerManager(readOnly: bool, applicationHostConfigurationPath: string) : unit
val createSite : siteName:string -> Site

Full name: Script.createSite
val siteName : string
property ServerManager.Sites: SiteCollection
ConfigurationElementCollectionBase.Add(element: Site) : Site
SiteCollection.Add(name: string, physicalPath: string, port: int) : Site
SiteCollection.Add(name: string, bindingInformation: string, physicalPath: string, certificateHash: byte []) : Site
SiteCollection.Add(name: string, bindingProtocol: string, bindingInformation: string, physicalPath: string) : Site
val applicationPool : poolName:string -> ApplicationPool

Full name: Script.applicationPool
val poolName : string
val livePool : ApplicationPool
type ApplicationPool =
  inherit ConfigurationElement
  member AutoStart : bool with get, set
  member Cpu : ApplicationPoolCpu
  member Enable32BitAppOnWin64 : bool with get, set
  member Failure : ApplicationPoolFailure
  member ManagedPipelineMode : ManagedPipelineMode with get, set
  member ManagedRuntimeVersion : string with get, set
  member Name : string with get, set
  member ProcessModel : ApplicationPoolProcessModel
  member QueueLength : int64 with get, set
  member Recycle : unit -> ObjectState
  ...

Full name: Microsoft.Web.Administration.ApplicationPool
property ServerManager.ApplicationPools: ApplicationPoolCollection
ConfigurationElementCollectionBase.Add(element: ApplicationPool) : ApplicationPool
ApplicationPoolCollection.Add(name: string) : ApplicationPool
property ApplicationPool.Enable32BitAppOnWin64: bool
property ApplicationPool.ManagedRuntimeVersion: string
val site : siteName:string * poolName:string -> unit

Full name: Script.site
val liveSite : Site
type Site =
  inherit ConfigurationElement
  member ApplicationDefaults : ApplicationDefaults
  member Applications : ApplicationCollection
  member Bindings : BindingCollection
  member GetWebConfiguration : unit -> Configuration
  member Id : int64 with get, set
  member Limits : SiteLimits
  member LogFile : SiteLogFile
  member Name : string with get, set
  member ServerAutoStart : bool with get, set
  member Start : unit -> ObjectState
  ...

Full name: Microsoft.Web.Administration.Site
property Site.ServerAutoStart: bool
property Site.ApplicationDefaults: ApplicationDefaults
property ApplicationDefaults.ApplicationPoolName: string
property Site.TraceFailedRequestsLogging: SiteTraceFailedRequestsLogging
property SiteTraceFailedRequestsLogging.Enabled: bool
property SiteTraceFailedRequestsLogging.Directory: string
val liveName : string

Full name: Script.liveName
val livePool : ApplicationPool

Full name: Script.livePool
val liveSite : unit

Full name: Script.liveSite
property ApplicationPool.Name: string
val accName : string

Full name: Script.accName
val accPool : ApplicationPool

Full name: Script.accPool
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
ServerManager.CommitChanges() : unit
Raw view Test code New version

More information

Link:http://fssnip.net/s1
Posted:9 years ago
Author:Dom Finn
Tags: iis