tags:

views:

108

answers:

1

Is there a way to programmatically check if ASP.NET is "allowed" in Web Service Extensions on IIS 6.0. I know I can set this by using aspnet_regiis.exe -i -enable, but how do I check this using code?

Regards Deepak

A: 

Here's a C# snippet of code that should do the trick:

using System.DirectoryServices

static void Main(string[] args)
{
    using (DirectoryEntry de = new DirectoryEntry("IIS://localhost/W3SVC"))
    {
        foreach (string ext in de.Properties["WebSvcExtRestrictionList"])
        {
            if (ext.StartsWith("1,") && ext.IndexOf("ASP.NET v1.1") != -1)
            {
                Console.WriteLine("ASP.NET 1.1 is enabled");
            }

            if (ext.StartsWith("1,") && ext.IndexOf("ASP.NET v2.0") != -1)
            {
                Console.WriteLine("ASP.NET 2.0 is enabled");
            }
        }
    }
}

You need to add a reference to the System.DirectoryServices assembly on the .NET tab of the Add References dialogue.

Kev
Thanks that worked !!
DEE