Click here to Skip to main content
Click here to Skip to main content
Go to top

IIsManager

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

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:

' 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", "test.site.nl")

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

        ' 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 + _
					AccessPermissionFlags.Write
        End Using

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

        ' Starts the website. It is stopped at creation by default.
        testsite.StartSite()

    End Using

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

History

  • 20th August, 2008: First publication

License

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

Share

About the Author

Marcel Wijnands
Web Developer Batavia Groep BV
Netherlands Netherlands
No Biography provided

Comments and Discussions

 
Generalhelp me PinmemberMohammad_ka4-Jan-10 1:38 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140905.1 | Last Updated 20 Aug 2008
Article Copyright 2008 by Marcel Wijnands
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid