gpt4 book ai didi

asp.net - 升级到 .NET 4.5 后 iFrame 解析器错误

转载 作者:行者123 更新时间:2023-12-02 05:22:26 24 4
gpt4 key购买 nike

我们最近将所有 WebForms 项目升级到 .NET 4.5,并在加载带有 iFrame 元素的页面时遇到解析器问题。我们已通过将 iFrameHtmlGenericControl 转换为 HtmlIframe 来纠正此问题。这纠正了我们在本地运行代码时的所有解析器错误。

当我们部署应用程序时,我们收到以下错误消息:

Parser Error Message: The base class includes the field 'frame', but its type (System.Web.UI.HtmlControls.HtmlIframe) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlGenericControl).**

当我使用 HtmlGenericControl 部署旧代码时,错误消失,表明即使我们已经安装了 .NET 4.5,服务器仍在使用旧版本?

我尝试删除并重新安装 .NET,确保向 IIS 注册 asp。

带有 IIS 7.5 和 .NET 4.5 的 Windows 2008 R2

最佳答案

基本问题是 ASP.NET 编译器(将 ASPX 和 ASCX 文件编译为 C# 或 VB 代码)从 Web 窗体 IFRAME 服务器控件生成的对象与该控件对应的变量类型之间不兼容。您的 Web 表单代码隐藏在后面。 IFRAME 服务器控件 ( <iframe id="frame" runat="server" /> ) 将被解析为特定类型的控件。在 ASP.NET 4 中,IFRAME 服务器控件将是 HtmlGenericControl 控件。在 ASP.NET 4.5 中,IFRAME 服务器控件将是 HtmlIframe 控件。

可以通过确保 web.config 文件中的编译元素上的 targetFramework 属性与项目的 Target Framework 属性一致并且与 IFRAME 服务器控件对应的变量与该控件的类型相匹配来解决此问题。 ASP.NET编译器将生成。

已在 Visual Studio 2013 中转换为 .NET Framework 4.5 的 ASP.NET 4 项目将修改项目的 web.config 文件,以便编译元素的 targetFramework 属性值为“4.5”( <compilation targetFramework="4.5"/> ) 。这会导致 ASP.NET 编译器将 IFRAME 服务器控件视为 HtmlIframe 控件。如果控件变量后面的 Web 窗体代码仍然是 HtmlGenericControl,这可能会导致问题。您看到的错误是这样的:

The base class includes the field 'frame', but its type (System.Web.UI.HtmlControls.HtmlGenericControl) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlIframe).

上一个错误的解决方案是更新 IFRAME 服务器控件对应的服务器控件变量的类型。您可以通过重新保存 Web 表单 HTML 文件来完成此操作,这将导致重新生成设计器文件。据我所知(至少在 Visual Studio 2013 中)没有必要更改控件 ID。如果服务器控制变量位于代码隐藏文件中,则必须手动更新。

如果 web.config 文件中编译元素的 targetFramework 属性的值为“4.0”( <compilation targetFramework="4.0"/> ),则变量后面的代码是 HtmlIframe 的 ASP.NET 4.5 项目将遇到类似但不同的问题。这会导致 ASP.NET 编译器将 IFRAME 服务器控件视为 HtmlGenericControl 控件。您看到的错误是这样的:

The base class includes the field 'frame', but its type (System.Web.UI.HtmlControls.HtmlIframe) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlGenericControl).

修复上述错误的方法是确保 web.config 编译设置与项目的目标框架属性一致。在这种情况下,web.config 中的compilation 元素的targetFramework 属性的值应为“4.5”。

<compilation targetFramework="4.5"/>

<小时/>

注意:将 httpRuntime 元素的 targetFramework 属性设置为 4.5 也会产生将compilation 元素的 targetFramework 属性设置为 4.5 的效果。请参阅https://devblogs.microsoft.com/dotnet/all-about-httpruntime-targetframework/了解更多信息。

注2:没有<asp:HtmlIframe>标签。使用 IFRAME 服务器控件不需要将标记前缀“asp”注册到 System.Web.UI.HtmlControls 命名空间。

关于asp.net - 升级到 .NET 4.5 后 iFrame 解析器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17809446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com