简体   繁体   English

Membership.CreateUser适用于多个会员提供商

[英]Membership.CreateUser for multiple Membership Providers

I am having trouble with handling multiple Membership Providers on one site. 我在一个站点上处理多个成员提供商时遇到问题。

I have a registration page that creates user and adds them to an AD domain. 我有一个注册页面,用于创建用户并将其添加到AD域。 Before I had one membership provider and on the page I called 在我有一个会员提供者之前,我打过电话

Membership.CreateUser(txtUsername.Text, txtPassword.Text) 

which created the username based on the user inputs on the page. 根据页面上的用户输入创建用户名。

However, I added another membership provider to the web.config so that the log in page can be used to log in from another AD. 但是,我在web.config中添加了另一个成员资格提供程序,以便可以使用登录页面从另一个AD登录。 Now, my registration page will not work because (I assume) there is two membership providers? 现在,我的注册页面不起作用,因为(我假设)有两个会员提供商?

How can I fix this? 我怎样才能解决这个问题? How do I specify which provider to use when I call Membership.CreateUser? 如何在调用Membership.CreateUser时指定要使用的提供程序?

Thanks. 谢谢。

Edit: 编辑:

The correct way to do this, as mentioned below is : 如下所述,正确的方法是:

MembershipCreateStatus newStatus = new MembershipCreateStatus();    
Membership.Providers["ProviderName"].CreateUser(txtUserName.Text, txtPassword.Text, null, null, null, true,null, out newStatus);

Thank you! 谢谢!

Membership.Providers["providername"].CreateUser(....);

Note that there is only one CreateUser method in this case but you can pass null of other parameters that are not needed. 请注意,在这种情况下只有一个CreateUser方法,但您可以传递其他不需要的参数的null。

Edit: 编辑:

That is the only way to call that method with explicit provider. 这是使用显式提供程序调用该方法的唯一方法。 I haven't tried creating user in AD so not sure about resolving that error but here is another way. 我没有尝试在AD中创建用户,所以不确定解决该错误,但这是另一种方式。 Make the provider for CreateUser as your defaultprovider and so you can go back to the old CreateUser call. 将CreateUser的提供程序作为defaultprovider,这样您就可以返回旧的CreateUser调用。 But now you adjust your login call to use another provider eg 但现在您调整登录呼叫以使用其他提供商,例如

Membership.Providers["providername"].ValidateUser()

There is a Providers property on Membership that contains a collection of the membership providers. 成员资格上有一个Providers属性,其中包含成员资格提供程序的集合 You should be able to discern which provider to use from there. 您应该能够从那里辨别使用哪个提供商。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#成员资格多个提供程序createuser错误 - C# membership multiple providers createuser error 扩展Membership.CreateUser方法的参数 - Extending parameters for Membership.CreateUser method 对Membership.CreateUser抛出“没有错误。” - “No Error.” thrown on Membership.CreateUser CreateUserWizard的哪种方法称为Membership.CreateUser? - What method of CreateUserWizard calls the Membership.CreateUser? 使用Membership.CreateUser时数据在哪里保留? - Where is data persisted when using Membership.CreateUser? ASP.Net在调用Membership.CreateUser()时设置正确的连接字符串 - ASP.Net Setting the correct Connection String when calling Membership.CreateUser() ASP.NET MVC 3 单元测试 Membership.CreateUser 总是返回 MembershipCreateStatus 错误 - ASP.NET MVC 3 unit tests for Membership.CreateUser always return MembershipCreateStatus error 成员资格CreateUser和相关表 - Membership CreateUser and related tables 通过Membership.CreateUser创建用户时,是否有一个.NET包装器可以设置用户的地址,城市,州,邮政编码等? - When creating a user by Membership.CreateUser, is there a .NET wrapper that can set the user's address, city, state, zip, etc.? 自定义成员资格提供程序存在的问题 - Problems with custom membership providers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM