Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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. 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?

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!

like image 633
Matt Kagan Avatar asked Dec 27 '22 20:12

Matt Kagan


2 Answers

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.

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. Make the provider for CreateUser as your defaultprovider and so you can go back to the old CreateUser call. But now you adjust your login call to use another provider e.g.

Membership.Providers["providername"].ValidateUser()
like image 200
gbs Avatar answered Jan 11 '23 20:01

gbs


There is a Providers property on Membership that contains a collection of the membership providers. You should be able to discern which provider to use from there.

like image 23
Forgotten Semicolon Avatar answered Jan 11 '23 20:01

Forgotten Semicolon