简体   繁体   中英

Enable ASP.NET in IIS6 Programmatically

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.

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

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

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);
}
// 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM