Creating a new member using Membership.CreateUser when I have multiple memberTypes
Hi All
I'm trying to come to grips with the new methodology for creating members in Umbraco dynamically.
I have a site that has 2 memberTypes, I'm getting the impression I need to set something in my web.config to specify what my default memberType is, but I don't really have one, as I expect my members to be about 50/50 split between the 2.
How should I tweak web.config to handle both types, or should I just try to do it programatically (if there's a way).
Both memberTypes will contain specific data that will need to be written to on creation, address, job title etc.
There are two ways you can create members - the "preferred" way is to use the built-in ASP.Net membership framework, which by default uses the umbraco membership provider. When you create a member this way, it uses the default member type set in the web.config.
The old and deprecated way to create members was to go directly to the umbraco Members api and call Members.MakeNew();. In fact, that's what the umbraco membership provider is actually doing, and for this reason alone I don't think that it should be marked as deprecated.
So to programmatically create a new Member while specifying a MemberType you could do the following (ripped shamelessly from the umbraco MembershipProvider with a little modification):
// using umbraco.cms.businesslogic.member; Member m = Member.MakeNew(username, email, MemberType.GetByAlias(memberType)); // Set the password m.Password = password;
// custom fields - the updateMemberProperty method is a private // helper method found in the MembershipProvider - it simply wraps around m.getProperty()
if (!String.IsNullOrEmpty(m_PasswordRetrievalQuestionPropertyTypeAlias)) updateMemberProperty(m, m_PasswordRetrievalQuestionPropertyTypeAlias, passwordQuestion);
if (!String.IsNullOrEmpty(m_PasswordRetrievalAnswerPropertyTypeAlias)) updateMemberProperty(m, m_PasswordRetrievalAnswerPropertyTypeAlias, passwordAnswer);
if (!String.IsNullOrEmpty(m_ApprovedPropertyTypeAlias)) updateMemberProperty(m, m_ApprovedPropertyTypeAlias, isApproved);
if (!String.IsNullOrEmpty(m_LastLoginPropertyTypeAlias)) { mUser.LastActivityDate = DateTime.Now; updateMemberProperty(m, m_LastLoginPropertyTypeAlias, mUser.LastActivityDate); }
// save m.Save();
After that, you could assign the rest of the properties on the member as specified by your chosen member type from whatever form you use to collect the info...
Thanks for this. In the end I did end up using the old methodology as you suggested. I'd have been quite happy using the new method, but couldn't find an example on the web that I could get to work. It would be great if they could put up some documentation on the site as I suspect they're only going to make it harder to use the umbraco member api as we go through further versions of the system.
Creating a new member using Membership.CreateUser when I have multiple memberTypes
Hi All
I'm trying to come to grips with the new methodology for creating members in Umbraco dynamically.
I have a site that has 2 memberTypes, I'm getting the impression I need to set something in my web.config to specify what my default memberType is, but I don't really have one, as I expect my members to be about 50/50 split between the 2.
How should I tweak web.config to handle both types, or should I just try to do it programatically (if there's a way).
Both memberTypes will contain specific data that will need to be written to on creation, address, job title etc.
Any help gratefully recieved.
Anyone?
Hi Shaun,
There are two ways you can create members - the "preferred" way is to use the built-in ASP.Net membership framework, which by default uses the umbraco membership provider. When you create a member this way, it uses the default member type set in the web.config.
The old and deprecated way to create members was to go directly to the umbraco Members api and call Members.MakeNew();. In fact, that's what the umbraco membership provider is actually doing, and for this reason alone I don't think that it should be marked as deprecated.
So to programmatically create a new Member while specifying a MemberType you could do the following (ripped shamelessly from the umbraco MembershipProvider with a little modification):
After that, you could assign the rest of the properties on the member as specified by your chosen member type from whatever form you use to collect the info...
- Rob.
Hi Rob
Thanks for this. In the end I did end up using the old methodology as you suggested. I'd have been quite happy using the new method, but couldn't find an example on the web that I could get to work. It would be great if they could put up some documentation on the site as I suspect they're only going to make it harder to use the umbraco member api as we go through further versions of the system.
is working on a reply...