自定义ASPNetMembership FailureInformation总是空,OnValidatingPassword问题 [英] Custom ASPNetMembership FailureInformation always null, OnValidatingPassword issue
问题描述
由于此处所述<一href="http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.onvalidatingpassword.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.onvalidatingpassword.aspx
当ValidatingPassword事件完成后,ValidatePasswordEventArgs对象的属性提供作为e参数可以进行检查,以确定当前的行为是否应被取消,如果一个特定的异常,存储在FailureInformation财产,应甩。
"When the ValidatingPassword event has completed, the properties of the ValidatePasswordEventArgs object supplied as the e parameter can be examined to determine whether the current action should be canceled and if a particular Exception, stored in the FailureInformation property, should be thrown."
下面是一些细节/ code这确实说明了为什么FailureInformation可能是空 HTTP:/ /forums.asp.net/t/991002.aspx
Here is some details/code which really shows why FailureInformation could be null http://forums.asp.net/t/991002.aspx
据我的会员设置我应该得到的异常密码不匹配密码的安全状况,但它没有发生。
According with my Membership settings i should get an exception that password does not match password security conditions, but it is not happened.
然后我也尝试调试System.Web.ApplicationServices.dll(在.NET 4.0中位于System.Web.Security中这里)框架code,看什么真的发生在那里,但我不能踏进这个组件,可是因为这个 [TypeForwardedFrom(System.Web程序,版本= 2.0.0.0,文化=中性公钥= b03f5f7f11d50a3a)
公共抽象类的MembershipProvider:的ProviderBase
Then i did try to debug System.Web.ApplicationServices.dll(in .NET 4.0 System.Web.Security located here) Framework Code to see whats really happens there, but i cant step into this assembly, may be because of this [TypeForwardedFrom("System.Web, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public abstract class MembershipProvider : ProviderBase
轻松我可以走进任何一家其他.NET 4.0组件,但在这一个没有。我没有检查,对System.Web.ApplicationServices.dll符号加载。
Easily i may step into any another .NET 4.0 assembly, but in this one not. I did check, symbols for System.Web.ApplicationServices.dll loaded.
现在我只有一个想法TI如何解决它 - 覆盖方法OnValidatingPassword(ValidatePasswordEventArgs E)
Now i have only one idea how ti fix it - to override method OnValidatingPassword(ValidatePasswordEventArgs e).
这就是我的故事。
可能有人可以帮助:
1)任何想法,为什么OnValidatingPassword不工作?
1) Any ideas why OnValidatingPassword not working?
2)任何想法如何步入它?
2) Any ideas how to step into it?
推荐答案
读过这个 HTTP:/ /forums.asp.net/t/991002.aspx 一次。下面是我的解决方案
Have read this http://forums.asp.net/t/991002.aspx one more time. Here is my solution
//Override OnValidatingPassword
protected override void OnValidatingPassword(ValidatePasswordEventArgs args)
{
//Any logic to process password validation conditions
//e.g:
if (args.Password.Length < MinRequiredPasswordLength)
args.FailureInformation = new ArgumentException(String.Format("Password is too short, min password length {0}", MinRequiredPasswordLength.ToString()));
if (args.UserName == args.Password)
args.FailureInformation = new ArgumentException(String.Format("Password should not be equal to username"));
//Also here could be any logic to throw an exception if needed
//e.g:
if (args.FailureInformation != null)
throw args.FailureInformation;
//Calling base
base.OnValidatingPassword(args);
if (args.Cancel)
{
if (args.FailureInformation == null)
args.FailureInformation = new ArgumentException(String.Format("Custom Password Validation Failure for password '{0}'", args.Password));
throw args.FailureInformation;
}
}
这篇关于自定义ASPNetMembership FailureInformation总是空,OnValidatingPassword问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!