有没有办法自定义 Active Directory 异常/错误消息?

发布于 2024-11-09 04:42:14 字数 304 浏览 0 评论 0原文

我使用 Active Directory 作为网站用户的数据存储。如果密码不满足任何密码策略约束,我的 Active Directory 会抛出以下异常。

-->提供的密码无效。 密码必须与密码一致 配置的强度要求 默认提供程序。

我可以以任何方式自定义此错误消息/通知以使其更加具体吗?

我想要的是 - 如果“密码历史记录”是被违反的约束,那么错误消息应该这样说(例如新密码应该与最近 10 个使用的密码不同..

任何帮助受到赞赏。

I am using Active 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扭转时空 2024-11-16 04:42:14

你可以捕获它并抛出你自己的消息

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;
}

这是你想要完成的吗?

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?

泡沫很甜 2024-11-16 04:42:14

那么您应该看到抛出的异常的确切类型,并为此异常设置特定的catch

如果您看到此链接,http://msdn.microsoft.com/en-us /library/0yd65esw.aspx,您将看到可以捕获多个特定的异常。

然后您可以将您想要的任何消息返回给用户。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文