Introduction
This Class Library will allow you to create and modify websites, application pools, virtual directories, etc. in IIS6 using .NET.
Background
If you ever needed to automate the creation of web applications, application pools, virtual directories, etc. you might find this IIsManager
Class Library I made to be very useful. Using the System.DirectoryServices
namespace to manage IIS 6 is not very straightforward, so I decided to wrap IIS 6 into these classes:
IIsService
IIsApplicationPool
IIsSite
IIsDirectory
IIsFile
IIsVirtualDirectory
After instantiating the IIsService
class, you can use it to iterate through sites (using LINQ if you want), adding or removing them, and set properties on them.
Using the Code
The following example will create a website, set it to use ASP.NET 2.0, create an application pool and set the website to use it, change access permissions on a directory and create a virtual directory containing a web application:
Using IIsSvc = New IIsService
Using testsite = IIsSvc.AddSite("TestSite", "c:\inetpub\testsite", "test.site.nl")
testsite.AccessPermissions = AccessPermissionFlags.Read + _
AccessPermissionFlags.Script
testsite.ASPNETVersion = ASPNETVersions.v2_0_50727
Dim testpool = IIsSvc.AddAppPool("testpool")
testsite.ApplicationPoolId = testpool.Id
Using images = testsite.AddDirectory("images")
images.AccessPermissions = AccessPermissionFlags.Read + _
AccessPermissionFlags.Write
End Using
Using newapp = testsite.AddVirtualDirectory("newapp", "c\inetpub\newapp")
newapp.CreateApplication()
newapp.AccessPermissions = AccessPermissionFlags.Read + _
AccessPermissionFlags.Script
End Using
testsite.StartSite()
End Using
End Using
History
- 20th August, 2008: First publication