Asp.Mvc 2.0用户登录实例讲解---(4)服务器端验证(3)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-26 22:13 点击:次
public override string FormatErrorMessage(string name)
{
return ErrorMessage;
}
/// <summary>
/// 重写TYPEID
/// </summary>
public override object TypeId
{
get
{
return _typeid;
}
}
/// <summary>
/// 判断是否想到
/// </summary>
/// <param name="value">value的值实际上是MODEL提交的MODEL类</param>
/// <returns></returns>
public override bool IsValid(object value)
{
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value);
object originalValue = properties.Find(PWD, true ).GetValue(value);//获取密码
object confirmValue = properties.Find(ConfirmPwd, true).GetValue(value);//获取确认密码的值
return Object.Equals(originalValue, confirmValue);
}
}
/// <summary>
/// 此自定义类用于验证密码和确认密码必须一致
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public class PwdMatch :ValidationAttribute
{
private object _typeid = new object();
public string PWD { get; set; }//密码
public string ConfirmPwd { get; set; }//确认密码
public PwdMatch(string pwd, string confirmPwd)
: base()
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>