ActiveDirectoryMembershipProvider 用于验证用户

发布于 2024-10-12 16:27:29 字数 623 浏览 3 评论 0原文

我想使用 ActiveDirectoryMembershipProvider 的 ValidateUser 方法来验证 AD 中是否存在用户。

我正在以表格形式输入用户名和密码。然后我想实例化提供程序并调用 ValidateUser

<add name="AspNetActiveDirectoryMembershipProvider" 
     type="System.Web.Security.ActiveDirectoryMembershipProvider" 
     connectionStringName="ADConnection" 
     attributeMapUsername = "userPrincipalName"  />

我只是将实际值替换为帖子的测试。

<add name="ADConnection" connectionString="LDAP://test.test.test.com/dc=test,dc=com" />

为了做我想做的事情,我是否需要向提供程序提供用户名和密码所以它可以首先连接,即系统帐户..一旦建立,我就可以检查我想要验证的用户?

谢谢, J

I would like to use the ValidateUser method of the ActiveDirectoryMembershipProvider to validate that a user exists in AD.

I am taking in the username and password in a form. I would like to then instantiate the provider and call ValidateUser

<add name="AspNetActiveDirectoryMembershipProvider" 
     type="System.Web.Security.ActiveDirectoryMembershipProvider" 
     connectionStringName="ADConnection" 
     attributeMapUsername = "userPrincipalName"  />

I just replace real values with test for the post..

<add name="ADConnection" connectionString="LDAP://test.test.test.com/dc=test,dc=com" />

To do what I want to do, do i need to provide a username and password to the provider so it can connect in first place, i.e. a system account.. and once its established I can then check the user I want to validate?

Thanks,
J

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

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

发布评论

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

评论(1

烏雲後面有陽光 2024-10-19 16:27:29

使用 ASP.NET 会员系统,重点是您不需要实例化提供程序类或任何其他内容 - 您定义的提供程序类可立即在 Membership 静态实例下使用。

因此,在您的情况下,只需确保配置正确,然后执行以下操作:

 if (Membership.ValidateUser(UsernameTextbox.Text, PasswordTextbox.Text))
     FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckBox.Checked);
 else
     Msg.Text = "Login failed. Please check your user name and password and try again.";

Membership 将是您定义的必要类 - 只需调用其静态方法即可完成! :-)

更新: 看来您应该能够按照这些方式轻松实例化多个会员资格提供程序:

    if (e.UserName.IndexOf("@contoso.com") >= 0)
    {
        e.Authenticated = Membership.Providers["ContosoSqlProvider"].ValidateUser(e.UserName, e.Password);
    }
    else if (e.UserName.IndexOf("@fabrikam.com") >= 0)
    {
        e.Authenticated = Membership.Providers["FabrikamSqlProvider"].ValidateUser(e.UserName, e.Password);
    }
    else
    {
        e.Authenticated = Membership.Provider.ValidateUser(e.UserName, e.Password);
    }

所以基本上,您可以通过 Membership.Providers[ 访问它来获取特定的会员资格提供程序"FabrikamSqlProvider"],然后调用其方法,例如 .ValidateUser()

基本的 Membership.ValidateUser 将仅使用您定义为默认的成员资格提供程序 - 但这不会阻止您使用其他提供程序!

With the ASP.NET membership system, the whole point is you don't need to instantiate a provider class or anything - the one you've defined is available right away under the Membership static instance.

So in your case, just make sure the config is correct, and then do something like:

 if (Membership.ValidateUser(UsernameTextbox.Text, PasswordTextbox.Text))
     FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckBox.Checked);
 else
     Msg.Text = "Login failed. Please check your user name and password and try again.";

The Membership will be the necessary class you've defined - just call the static methods on it and be done with it! :-)

Update: it appears you should be able to easily instantiate multiple membership providers along those lines here:

    if (e.UserName.IndexOf("@contoso.com") >= 0)
    {
        e.Authenticated = Membership.Providers["ContosoSqlProvider"].ValidateUser(e.UserName, e.Password);
    }
    else if (e.UserName.IndexOf("@fabrikam.com") >= 0)
    {
        e.Authenticated = Membership.Providers["FabrikamSqlProvider"].ValidateUser(e.UserName, e.Password);
    }
    else
    {
        e.Authenticated = Membership.Provider.ValidateUser(e.UserName, e.Password);
    }

So basically, you can get a specific membership provider by accessing it through Membership.Providers["FabrikamSqlProvider"] and then call methods on it, like .ValidateUser().

The basic Membership.ValidateUser will simply use the membership provider you've defined as the default - but it doesn't stop you from using others!

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