I am using Ac开发者_StackOverflowtive Directory as a data store for the users of my website. I have Active Directory throwing the following exception in case password does not meet any password policy constraint..
-->The password supplied is invalid. Passwords must conform to the password strength requirements configured for the default provider.
Can I customize this error messages/notifications in any way to be them more specific??
What I want is that - If 'password history' is the constraint that is violated then the error message should say so (ex. New password should be different than the last 10 used passwords..)
Any help is appreciated.
you can catch that and throw
you own message
try {
// your error will probably appear here
if (MembershipService.ValidateUser(usr, pwd))
{
...
}
}
catch(Exception ex)
{
// Let's see if we have Inner Exceptions to deal
if(ex.InnerException != null)
while(ex.InnerException != null)
ex = ex.InnerException;
// Now, let's check our exception
if(ex.Message.StartsWith("The password supplied is invalid. Passwords must conform to the password strength requirements configured for the default provider."))
{
throw new Exception("My custom message goes here");
}
// Let's throw the original one
throw ex;
}
Is this what you are trying to accomplish?
Well you should see the exact type of Exception that is thrown, and setup a specific catch for this exception.
If you see this link, http://msdn.microsoft.com/en-us/library/0yd65esw.aspx, you will see that you can catch multiple specific Exceptions.
You could then return whatever msg you want to the user.
精彩评论