c# - Windows 7 IIS 7.5 与 System.ComponentModel.Browsable 属性的奇怪行为

标签 c# asp.net iis-7.5

我只是想看看其他人是否有与我相同的行为。

我有一个名为 GridViewEx 的类,它扩展了 GridView。该类中的属性之一将 Browsable(true) 作为注释。这允许(至少在 IIS 7.5 之前)在标记中设置属性。但在 Windows 7 IIS 7.5 上,它会给出解析器错误。请注意,在具有 IIS 7.5 的 Win 2008 服务器上,该应用程序运行良好。

所以我想知道是否是 Win7 中的某些 IIS 7.5 设置搞砸了。

重现步骤

a) 创建新的 ASP.Net 应用程序,框架版本使用 4.0

b) 创建一个名为 GridViewEx 的新类(获取/设置只是虚拟代码,并不重要):

namespace GUI.Controls
    {
        public class GridViewEx : GridView
        {
            [Browsable(true)]
            [Description("my test")]
            public int VirtualItemCount
            {
                get
                {
                    return 42;
                }
                set
                {
                    int x = value;
                    int y = x + x;
                }
            }

        }
    }

c) 在 Default.aspx 中,注册标记前缀(将 WebApplication1 更改为您为项目命名的任何名称)。该行应该位于 Page 指令的正下方。

<%@ Register TagPrefix="common" Namespace="GUI.Controls" Assembly="WebApplication1" %>

d) 在 Default.aspx 中,将其添加到您的内容中:

<common:GridViewEx runat="server" ID="gv" VirtualItemCount="-1">

</common:GridViewEx>

如果我在 IIS 7.0 或更早版本上运行此应用程序,则不会出现任何错误。但是,在 Win 7 IIS 7.5 上,出现以下错误:

Parser Error 
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: The 'VirtualItemCount' property cannot be set declaratively.

我不明白为什么我在 Win 7 IIS 7.5 上收到错误,但在早期 IIS 版本上却没有,在 Win 2008 服务器上的 IIS 7.5 上也没有。有什么想法吗?

最佳答案

好的,我找到了一个可行的方法。将这些属性添加到VirtualItemCount:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[EditorBrowsable(EditorBrowsableState.Always)]
[Bindable(true)]

现在我不再收到解析器错误。我不明白为什么我必须添加这些才能在我的 Win 7 机器上工作,但是在服务器上我测试了不需要这些额外的属性(我的 Win 7 机器和服务器都在 IIS 7.5 上) 。我想这仍然是一个谜。

非常感谢回答的人this question ,因为它引导我走向正确的方向。

关于c# - Windows 7 IIS 7.5 与 System.ComponentModel.Browsable 属性的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14899899/

相关文章:

c# - 有没有办法在 Monogame 中使用剪贴板?

c# - 使用 int 和 uint 的区别以及何时使用

javascript - 使用单选按钮、highcharts、vb.net 从服务器获取数据

启用磁盘缓存时出现 Azure ARR 错误

asp.net - ASP.NET 4.0 和 SQL2008R2 中的 Kerberos 双跃点

c# - 产生多个 IEnumerables

c# - 带有自定义参数的事件处理程序

asp.net - 如何在不延迟 ASP.NET 响应的情况下发送电子邮件?

javascript - 大量的 onclick 元素...或者一些 jquery

iis-7.5 - "appcmd start site"命令失败并显示消息 "The object identifier does not represent a valid object."