IIS 10.0 上的旧 asp.net 应用无法识别元素 'compilers'

Unrecognized element 'compilers' with old asp.net app on IIS 10.0

我希望有人能够帮助我们解决我遇到的 IIS / ASP.NET 问题。我的任务是将 ASP.NET 网站从 Windows 2003 32 位服务器上的 IIS 6 移动到 Windows 2016 64 位服务器上的 IIS 10。 我已经使用 PowerShell 安装了 IIS 和 .NET 3.5 Framework,其中包括 .NET 2.0 和 3.0,具有以下功能

$featureList = @('Web-Server','Web-CertProvider','Web-IP-Security','Web-Windows-Auth','Web-Asp-Net', 'NET-Framework-Features')
Install-WindowsFeature -Name $installFeatures -IncludeManagementTools -Source 'D:\sources\sxs' -Restart

接下来创建我的应用程序池和站点如下

New-WebAppPool -Name 'MyApp_AppPool'
Get-Item -Path 'IIS:\AppPools\MyApp_AppPool' | Set-ItemProperty -Name managedRuntimeVersion -Value 'v2.0'
New-Website -Name MyApp -ApplicationPool MyApp_AppPool -HostHeader myapp.domain.ca -IPAddress * -PhysicalPath 'E:\inetpub\wwwroot\MyApp' -Port 80

该站点似乎加载了登录页面,但是在 IIS 管理器中,如果我转到 .NET 编译,我会收到以下错误消息。 执行此操作时出错。

Details:
Filename: \?\E:\inetpub\wwwroot\PEIWeb\web.config
Line number: 25
Error: Unrecognized element ‘compilers’

这里是 web.config 文件的专家

    <compilation defaultLanguage="vb" debug="true">
        <compilers>
            <compiler language="vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" extension=".VB" compilerOptions="/define:Debug=True /define:Trace=True /imports:Microsoft.VisualBasic,System,System.Collections,System.Configuration,System.Data,System.Drawing,System.Web,System.Web.UI,System.Web.UI.HtmlControls,System.Web.UI.WebControls" />
        </compilers>
        <assemblies>
            <add assembly="Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
            <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            <add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        </assemblies>
    </compilation>

我已经测试了托管管道模式设置为集成和经典的应用程序池,并且还测试了将启用 32 位应用程序设置为 True,但我仍然遇到相同的错误。

我在网上看到如果在安装 .NET 3.5 Framework 之前安装 IIS 可能会出现此类错误,所以我使用重新启动的服务器管理器、安装的 .NET 3.5 Framework 和重新启动并安装了 IIS 来卸载它们,但是我仍然遇到同样的错误。

我也试过 运行 aspnet_regiis.exe -i 来自以下两个文件夹,但我仍然收到同样的错误。

C:\Windows\Microsoft.NET\Framework\v2.0.50727 C:\Windows\Microsoft.NET\Framework64\v2.0.50727

如果有人对如何解决这个问题有任何建议,我将不胜感激。

谢谢

所以我进行了更多的挖掘,终于找到了问题所在。

根据 Microsoft 的说法,compilation 元素下的 compilers 元素在 .NET Framework 2.0 中已贬值,但仍受支持。最后我将编译器和编译器元素放在 system.codedom 元素

https://msdn.microsoft.com/en-ca/library/5tc5kc3e(v=vs.80).aspx https://msdn.microsoft.com/en-ca/library/e4hwk57e(v=vs.80).aspx

所以现在不用这个

<configuration>
    <system.web>
        <compilation defaultLanguage="vb" debug="true">
            <compilers>
                <compiler language="vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" extension=".VB" compilerOptions="/define:Debug=True /define:Trace=True /imports:Microsoft.VisualBasic,System,System.Collections,System.Configuration,System.Data,System.Drawing,System.Web,System.Web.UI,System.Web.UI.HtmlControls,System.Web.UI.WebControls" />
            </compilers>
            <assemblies>
                <add assembly="Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
                <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
                <add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            </assemblies>
        </compilation>
    </system.web>
</configuration>

我有这个

<configuration>
    <system.web>
        <compilation defaultLanguage="vb" debug="true">
            <assemblies>
                <add assembly="Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
                <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
                <add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            </assemblies>   
        </compilation>
    </system.web>
    <system.codedom>
        <compilers>
            <compiler
                language="vb" 
                extension=".vb"
                type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"
                compilerOptions="/define:Debug=True /define:Trace=True /imports:Microsoft.VisualBasic,System,System.Collections,System.Configuration,System.Data,System.Drawing,System.Web,System.Web.UI,System.Web.UI.HtmlControls,System.Web.UI.WebControls"
            />
        </compilers>
   </system.codedom>
</configuration>

现在一切正常。 似乎虽然原始 web.config 文件使用的是贬值语法,但它仍然被 IIS 6 接受,并且看起来它不再被 IIS 10 接受。

无论如何,希望这对其他人有所帮助。