How to get the providerUserKey to create a user if I have 2 membership providers

How to get the providerUserKey to create a user if I have 2 membership providers

Postby JORGEMAL » Wed 21 Jan 2015 00:59

I wonder if this post belongs to this forum. Please let me know if I should ask somewhere else.

I need to use 2 different Membership providers in my web application so I have set both of them in the web.config file. The 2 of them are based on Devart for PostgreSQL with the only difference that they need a different connection string each one. I see that, to create a new user with this approach, I need to issue the following command in code:

Code: Select all
Membership.Providers["nameOfProvider"].CreateUser(string UserName, string Password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status);


How do I get the providerUserKey "before" creating the user?

I found the information in the link below but I just do not get the idea, however I see that in my case it is related to the MembershipProvider, that is why I think that you can help.
https://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.provideruserkey(v=vs.110).aspx
JORGEMAL
 
Posts: 164
Joined: Thu 03 Jul 2008 23:55

Re: How to get the providerUserKey to create a user if I have 2 membership providers

Postby Pinturiccio » Fri 23 Jan 2015 16:56

JORGEMAL wrote:How do I get the providerUserKey "before" creating the user?

You need to pass a Guid value to the providerUserKey parameter. Here is the sample that creates a user.

In this sample the 'g' variable stores a value. If you need any specific value, create a Guid with this value. This is how you can assign the providerUserKey value to the 'g' variable before creating the user.
Code: Select all
MembershipCreateStatus status;
Guid g = Guid.NewGuid();
Membership.Providers["nameOfProvider"].CreateUser("testuser", "1111111", "asda", "gg", "gg", true, g, out status);


You can also assign a 'null' value to the providerUserKey parameter. In this case our code generates a random Guid for this parameter.
Pinturiccio
Devart Team
 
Posts: 1978
Joined: Wed 02 Nov 2011 09:44


Return to dotConnect for PostgreSQL