5,693,062 members and growing! (17,913 online)
Email Password   helpLost your password?
Web Development » Site & Server Management » General     Beginner License: The Microsoft Public License (Ms-PL)

IIsManager

By Marcel Wijnands

Manage IIS 6 in .NET
VB (VB 9.0, VB), Windows (Windows, Win2003), .NET (.NET, .NET 3.5), IIS (IIS 6, IIS), SysAdmin, Dev

Posted: 20 Aug 2008
Updated: 20 Aug 2008
Views: 2,845
Bookmarked: 14 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
6 votes for this Article.
Popularity: 3.37 Rating: 4.33 out of 5
1 vote, 16.7%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
1 vote, 16.7%
4
4 votes, 66.7%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

This ClassLibrary 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 ClassLibrary 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, changes access permissions on a directory and creates 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

This is the first publication.

License

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

About the Author

Marcel Wijnands



Occupation: Web Developer
Company: Batavia Groep BV
Location: Netherlands Netherlands

Other popular Site & Server Management articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
GeneralMIMEmemberAnton_Lustin2:24 13 Nov '08  
GeneralVery Nicememberhericksonn9:33 30 Oct '08  
GeneralNice Jobmemberashu fouzdar21:25 26 Aug '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 20 Aug 2008
Editor:
Copyright 2008 by Marcel Wijnands
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project