使用System.ComponentModel.BrowseableAttribute赢得7 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的新类(get / set只是虚拟代码,不重要):
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指令下面。
d)在Default.aspx中,将其添加到您的内容中:
如果我在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上) 。 我想这仍然是一个谜。
非常感谢回答这个问题的人,因为它引导我朝着正确的方向前进。