自定义服务器控件 继承不到父类/基类的 SupportsEventValidation 特性. 不及格的程序员

作者:不及格的程序员-八神


MSDN 根本没有说它不可以继承, 事实上它真是不能继承.

在SupportsEventValidationAttribute类的源码中可以看到注释
Note that this attribute does not inherit from the base class, since derived classes may not be able to validate properly.

我更愿意看到比较明确的声明,例如:
[AttributeUsageAttribute(AttributeTargets.Class, Inherited = false, AllowMultiple = false)],而它没有这样声明.


看看可序列化特性的声明,明确了它不能继承,所以我们在写要序列化类时必须带有该特性的声明.

[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Delegate, Inherited = false)]
public
sealed class SerializableAttribute : Attribute 



这个属性是ASP.NET 2.0新增的 是为了验证用户控件回发的数据有效性 比如下拉列表盒,本身提供1到31天的选择,但是客户端修改了数据 提交了一个32的值,那么这时ASP.NET框架就会抛出异常,说提交数据非法. 有很多控件都会作这样的验证,如:Dropdownlist checkbox... 开发用户自定义控件,如果要验证数据的安全性,可以参考一下.

原文地址:https://www.cnblogs.com/ioriwellings/p/1566946.html