我只是想看看其他人是否有与我相同的行为。
我有一个名为 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/