PasswordRecovery 和 MembershipPasswordException 问题
我的网站中有一个PasswordRecovery 控件。
我有自己的自定义类实现 MembershipProvider。
其中一种方法是 GetPassword,以用户名、答案作为参数。
当用户输入问题的答案时它被激活,并且该方法应该检查答案是否正确。
据我了解,如果答案不正确,我应该抛出 MembershipPasswordException。
throw new MembershipPasswordException("MyMessage");
当我在调试模式下进行操作时,VS(2005...) 给出了以下运行时错误
MembershipPasswordException 未由用户代码处理,
但在客户端,它看起来像一切都按计划进行,用户收到一条错误消息,指出无法验证答案。
那么为什么我会收到此错误?没关系吗?
我做错了什么?
谢谢
编辑,这是有问题的代码:
conn = GetConnection();
command = new SqlCommand("CustomMemProvider_GetPassword", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("ApplicationID", ApplicationID));
command.Parameters.Add(new SqlParameter("UserName", username));
command.Parameters.Add(new SqlParameter("Answer", Encrypt(answer)));
SqlParameter pPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 256);
pPassword.Direction = ParameterDirection.Output;
SqlParameter pStatusMessage = new SqlParameter("@StatusMessage", SqlDbType.NVarChar, 256);
pStatusMessage.Direction = ParameterDirection.Output;
command.Parameters.Add(pPassword);
command.Parameters.Add(pStatusMessage);
command.ExecuteNonQuery();
string passToDecrypt = Parse.ObjectToString(pPassword.Value);
if (passToDecrypt == String.Empty)
throw new MembershipPasswordException(Parse.ObjectToString(pStatusMessage.Value));
else
password = Decrypt(Parse.ObjectToString(passToDecrypt));
I have a PasswordRecovery control in my site.
I have my own customized class implementing MembershipProvider.
One of the methods is GetPassword, with username, answer as parameters.
it is activated when the user enters an answer for the question, and the method should check if the answer is correct.
as I understand, if the answer is incorrect, I should throw a MembershipPasswordException.
throw new MembershipPasswordException("MyMessage");
when I go through it on debug mode, VS(2005...) gives me the following Runtime Error
MembershipPasswordException was unhandled by user code
but in the client side it seems like everything is working according to the plan, the user gets an error message saying the answer could not be verified.
So why do I get this error? is it ok anyway?
what am I doing wrong?
thanks
EDIT, this is the problematic code:
conn = GetConnection();
command = new SqlCommand("CustomMemProvider_GetPassword", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("ApplicationID", ApplicationID));
command.Parameters.Add(new SqlParameter("UserName", username));
command.Parameters.Add(new SqlParameter("Answer", Encrypt(answer)));
SqlParameter pPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 256);
pPassword.Direction = ParameterDirection.Output;
SqlParameter pStatusMessage = new SqlParameter("@StatusMessage", SqlDbType.NVarChar, 256);
pStatusMessage.Direction = ParameterDirection.Output;
command.Parameters.Add(pPassword);
command.Parameters.Add(pStatusMessage);
command.ExecuteNonQuery();
string passToDecrypt = Parse.ObjectToString(pPassword.Value);
if (passToDecrypt == String.Empty)
throw new MembershipPasswordException(Parse.ObjectToString(pStatusMessage.Value));
else
password = Decrypt(Parse.ObjectToString(passToDecrypt));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论