PasswordRecovery 和 MembershipPasswordException 问题

发布于 2024-11-18 23:27:35 字数 1767 浏览 2 评论 0原文

我的网站中有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文