Click here to Skip to main content
13,860,571 members
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 20 Aug 2008
Licenced Ms-PL


, 20 Aug 2008
Rate this:
Please Sign up or sign in to vote.
Manage IIS 6 in .NET


This Class Library will allow you to create and modify websites, application pools, virtual directories, etc. in IIS6 using .NET.


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:

' Instantiate an IIsService which represents the W3SVC service on the localhost.
Using IIsSvc = New IIsService

    ' Creates an IIsSite.
    Using testsite = IIsSvc.AddSite("TestSite", "c:\inetpub\testsite", "")

        ' Sets AccessPermissions to allow reading and executing scripts (.aspx).
        testsite.AccessPermissions = AccessPermissionFlags.Read + _

        ' Sets the website to use ASP.NET 2.0
        testsite.ASPNETVersion = ASPNETVersions.v2_0_50727

        ' Create an IIsApplicationPool.
        Dim testpool = IIsSvc.AddAppPool("testpool")

        ' Set the site to use the new application pool.
        testsite.ApplicationPoolId = testpool.Id

        ' Creates an IIsDirectory and changes the AccessPermissions 
        ' to allow writing to it.
        ' Note that the physical directory already has to exist 
        ' since we're just creating metabase information.
        Using images = testsite.AddDirectory("images")
            images.AccessPermissions = AccessPermissionFlags.Read + _
        End Using

        ' Creates an IIsVirtualDirectory and creates a Web application in it.
        Using newapp = testsite.AddVirtualDirectory("newapp", "c\inetpub\newapp")
            newapp.AccessPermissions = AccessPermissionFlags.Read + _
        End Using

        ' Starts the website. It is stopped at creation by default.

    End Using

    ' Because the classes implement IDisposable, 
    ' the Dispose method is automatically called
    ' at 'End Using'.
End Using


  • 20th August, 2008: First publication


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Marcel Wijnands
Software Developer (Senior)
Netherlands Netherlands
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Jeffrey Schaefer16-Dec-11 17:50
memberJeffrey Schaefer16-Dec-11 17:50 
Generalhelp me Pin
Mohammad_ka4-Jan-10 2:38
memberMohammad_ka4-Jan-10 2:38 
GeneralMIME Pin
Anton_Lustin13-Nov-08 2:24
memberAnton_Lustin13-Nov-08 2:24 
GeneralRe: MIME Pin
Marcel Wijnands19-Dec-08 1:37
professionalMarcel Wijnands19-Dec-08 1:37 
GeneralVery Nice Pin
hericksonn30-Oct-08 9:33
memberhericksonn30-Oct-08 9:33 
GeneralNice Job Pin
Ashutosh Phoujdar26-Aug-08 21:25
memberAshutosh Phoujdar26-Aug-08 21:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190214.1 | Last Updated 20 Aug 2008
Article Copyright 2008 by Marcel Wijnands
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid