4

Is there a way to enable the ASP.NET Web Service Extension in IIS6 via C#? I'm trying to simplify a website setup program for people who haven't used IIS before.

5 Answers 5

4

C# NET. Framework usage:

Process.Start(@"C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis", "-i -enable");

CMD usage:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -i -enable

It's useful.

Source: https://serverfault.com/questions/1649/why-does-iis-refuse-to-serve-asp-net-content

Sign up to request clarification or add additional context in comments.

Comments

2

You could call out to WMI easily enough (System.Management namespace, IIRC) and I believe you can set it from there. However, it may well be much simpler to set it manually, you can't do it from within an ASP.NET site since your server won't be able to run it until it is set...

Principles of doing something similar may be found here

1 Comment

Thanks, I want to set it up from post install action I have.
2

Looking around all the examples of this are written in vbscript. So I cheated and came up with this function:

static void EnableASPNET()
{
    var file = "wmi.vbs";
    using (var writer = new StreamWriter(file))
    {
        writer.WriteLine("Set webServiceObject = GetObject(\"IIS://localhost/W3SVC\")");
        writer.WriteLine("webServiceObject.EnableWebServiceExtension \"ASP.NET v2.0.50727\"");
        writer.WriteLine("webServiceObject.SetInfo");
    }
    var process = Process.Start("cscript", file);
    process.WaitForExit();
    File.Delete(file);
}

Comments

1
// if windows 2003
if (Environment.OSVersion.Version.Major == 5 &&
Environment.OSVersion.Version.Minor == 2)
{
  DirectoryEntry folderRoot = new DirectoryEntry("IIS://localhost/W3SVC");
  folderRoot.Invoke("EnableWebServiceExtension", "ASP.NET v2.0.50727");
}

Copied from: http://lastdon.blogspot.com/2006/12/setup-web-application-on-windows-2003.html

Comments

0

I believe you can also run the following command line:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -s W3SVC

And this will recursively enable the AND.NET framework v2.0.50727 for all configured websites.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.