问题
If I call user.ChangePassword(oldpass,newpass), and the old password is wrong, or the new password does not meet the provider's complexity requirement , the method fails without warning. is there any way i can find out if there is an error and what the error was.
I can always put these checks in my code, but there should be a way to do it using the Membership APIs
回答1:
Unfortunately not. The ChangePassword method only returns a simple bool for success/fail.
Your best option on fail would be to display a generic message to the user stating all possible failure reasons... e.g.
Failed to Change Password.
This may have occured because:
- The Old Password was incorrect
- The New Password failed to meet the required complexibility
- New Passwords must be 8 chars long and contain at least 2 numeric characters. (or whatever)
If you want to give more specific information, then as you said, you would need to implement a rules checker in your own code and relay information to the user based on that check.
来源:https://stackoverflow.com/questions/892256/membershipuser-changepassword-fails-without-warning