ActiveDirectoryMembershipProvider来验证用户 [英] ActiveDirectoryMembershipProvider to validate a user
问题描述
我想用ActiveDirectoryMembershipProvider的的ValidateUser
方法来验证用户在AD存在。
I would like to use the ValidateUser
method of the ActiveDirectoryMembershipProvider to validate that a user exists in AD.
我是把在一个表单的用户名和密码。我想,然后实例化提供者,并呼吁的ValidateUser
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?
谢谢, Ĵ
推荐答案
与ASP.NET会员制,整点就是你不需要实例化一个提供者类,或任何东西 - 你已经定义了一个可用就在成员
静态实例下。
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);
}
因此,基本上,你可以通过 Membership.Providers [FabrikamSqlProvider]
访问它得到具体的成员提供程序,然后调用它的方法,如 .ValidateUser()
。
So basically, you can get a specific membership provider by accessing it through Membership.Providers["FabrikamSqlProvider"]
and then call methods on it, like .ValidateUser()
.
基本 Membership.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!
这篇关于ActiveDirectoryMembershipProvider来验证用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!