简体   繁体   English

以编程方式在 IIS6 中启用 ASP.NET

[英]Enable ASP.NET in IIS6 Programmatically

Is there a way to enable the ASP.NET Web Service Extension in IIS6 via C#?有没有办法通过 C# 在 IIS6 中启用 ASP.NET Web 服务扩展? I'm trying to simplify a website setup program for people who haven't used IIS before.我正在尝试为以前没有使用过 IIS 的人简化网站设置程序。

C# NET. C# 网络。 Framework usage:框架使用:

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

CMD usage: CMD用法:

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来源: 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.你可以很容易地调用 WMI(System.Management 命名空间,IIRC),我相信你可以从那里设置它。 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...但是,手动设置它可能要简单得多,您不能在 ASP.NET 站点内进行设置,因为您的服务器在设置之前将无法运行它...

Principles of doing something similar may be found here可以在这里找到做类似事情的原则

Looking around all the examples of this are written in vbscript.环顾四周,所有这些示例都是用 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复制自: 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.这将为所有配置的网站递归启用 AND.NET 框架 v2.0.50727。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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