Last post Nov 21, 2014 01:13 AM by May Wang
Nov 18, 2014 09:01 AM|dolittle|LINK
I've built a custom membershipprovider handling all possible scenarios. One of which is to further deal with manually triggered exceptions. What I can't figure out for some reason is how to access the exception thrown in the OnPasswordChangeError Method.
The server.GetLastError() returns a null. and what ever I do I can't get a hold of it. Or do I need to pass the exception somehow to the OnPasswordError method? The changepassword only returns a bool to trigger the OnPasswordChageError. So I need to be able
to access the exceptions here to be able to handle them.
any help as always much appreciated.
// On PasswordChangeEvent
new Exception("Password must be at least 6 characters long and " +
"contain at least one number and one special character.");
args.Cancel = true;
/// Raises the <see cref="E:System.Web.UI.WebControls.ChangePassword.ChangePasswordError"/> event when the user's password is not changed.
/// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
protected override void OnChangePasswordError(EventArgs e)
var evt = new MembershipEvent("Password error", this, 6, this.UserName, this.NewPassword);
var server = HttpContext.Current.Server;
Exception error = server.GetLastError();
this.ChangePasswordFailureText = error.ToString();
Nov 21, 2014 01:13 AM|May Wang|LINK
>What I can't figure out for some reason is how to access the exception thrown in the OnPasswordChangeError Method.
Do you mean that you want to access the exception content which is thrown in ChangePassword event from OnPasswordChangeError method? You may have a try to use a label to transfer the exception content. I mean you need to new the exception and
catch the exception in your ChangePassword method and assign the exception.ToString to the label. So you will get the label content from OnPasswordChangeError Method.
You can refer to the sample code in this link:
> The server.GetLastError() returns a null. and what ever I do I can't get a hold of it. Or do I need to pass the exception somehow to the OnPasswordError method?
I think you may not catch the exception in your change password method, you can set breakpoint to debug your code.
By the way, you may also have a try to customize the changepassword control with adding the validation.
asp changepassword control customization