Membership.CreateUser for multiple membership providers

I am having problems processing multiple membership providers on the same site.

I have a registration page that creates a user and adds him to the AD domain. Before I got one provider member, and on the page that I called

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

who created the username based on the user inputs on the page.

However, I added another membership provider to web.config so that the login page can be used to login from another AD. Now my registration page will not work because (I assume) there are two membership providers?

How can i fix this? How to specify which provider to use when calling Memberhip.CreateUser?

Thanks.

Edit:

The correct way to do this is as follows:

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

Thanks!

+4
source share
2 answers
 Membership.Providers["providername"].CreateUser(....); 

Note that in this case there is only one CreateUser method, but you can pass null to other parameters that are not needed.

Edit:

This is the only way to call this method with an explicit provider. I did not try to create a user in AD, so I was not sure about the resolution of this error, but here is another way. Make the provider for CreateUser your default, and you can return to the old call to CreateUser. But now you are setting up your login to use another provider, for example.

 Membership.Providers["providername"].ValidateUser() 
+8
source

In membership, there is a Providers property that contains a collection of membership providers. You must be able to recognize which provider to use from there.

+1
source

All Articles