Using Membership.CreateUser() Instead Of Member.MakeNew()
I am trying to not use the obsolete way of creating members, but am not understanding how I am supposed to do the following:
Assign a MemberType on creation?
Assign Property Values?
I tried to cast the 'MembershipUser' as a 'Member' but it doesn't like that! Also in regards to the properties, I saw a post a while back from the Aaron the Oz'star about putting properties in the web.config.
Call me lazy, but I have added all my properties on the MemberType already! I don't want to basically duplicate it in code (Seems long winded to me!)? I just want something like the good old...
Thanks for the link, I actually had it bookmarked in the end anyway...
<RANT>But it still defeats the object in my opinion - I cannot see why methods such as Member.MakeNew() have been flagged as obsolete when the other way of creating members and defining/using member properties seems extremely verbose and a duplication of work.
Say I need to add some more properties to a member, I have to add it via the umbraco UI and then go and add them into my class as public property's and then AGAIN in the web.config... I guess its just me</RANT>
I'll just stick the the original 'obsolete' way and just put up with the 'blue squiggly worms' telling me off in Visual Studio!!
It is not just you. I'm strugling with the same thing atm. Using the UmbracoMembershipProvider is no easy task. I did however have some luck assigning a member type and a property value to a member on creation.
Lets say you create a member type called "Standard member" with an alias of "StandardMember" in Umbraco. On the member type you create a tab called Info on whatever. On that tab create a property called Address witn an alias of address as a text string.
Now in the web.config make sure your UmbracoMembershipProvider looks like this:
The important part being that the defaultMemberTypeAlias value is the same as the alias of the member type you created. Now add the following to the web.config just below membership section:
Note that the name of the property is the same as the alias of the property you created on the member type in Umbraco. Now you should be able to create a member, assign it to a member type and add a property value with the following code:
var member = Membership.CreateUser("mads.krohn", "tester", "[email protected]"); // Roles.AddUserToRole(member.UserName, "Standard group"); <-- You can also add your new member to a group you created in Umbraco var profile = ProfileBase.Create(member.UserName); profile["address"] = "test address"; profile.Save();
If you are planning to use more than one member type is appears you are out of luck, and instead need to begin implementing your own membership provider. That however, is something I'm still strugling with and I haven't yet found out how to do it. I might make a new post asking for help on that one :)
Using Membership.CreateUser() Instead Of Member.MakeNew()
I am trying to not use the obsolete way of creating members, but am not understanding how I am supposed to do the following:
Hi Lee,
This is the post from Aaron: http://www.aaron-powell.com/umbraco-members-profiles. Maybe it's useful again.
Jeroen
Thanks for the link, I actually had it bookmarked in the end anyway...
<RANT>But it still defeats the object in my opinion - I cannot see why methods such as Member.MakeNew() have been flagged as obsolete when the other way of creating members and defining/using member properties seems extremely verbose and a duplication of work.
Say I need to add some more properties to a member, I have to add it via the umbraco UI and then go and add them into my class as public property's and then AGAIN in the web.config... I guess its just me</RANT>
I'll just stick the the original 'obsolete' way and just put up with the 'blue squiggly worms' telling me off in Visual Studio!!
It is not just you. I'm strugling with the same thing atm. Using the UmbracoMembershipProvider is no easy task.
I did however have some luck assigning a member type and a property value to a member on creation.
Lets say you create a member type called "Standard member" with an alias of "StandardMember" in Umbraco.
On the member type you create a tab called Info on whatever. On that tab create a property called Address witn an alias of address as a text string.
Now in the web.config make sure your UmbracoMembershipProvider looks like this:
<add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="StandardMember" passwordFormat="Hashed" />
The important part being that the defaultMemberTypeAlias value is the same as the alias of the member type you created.
Now add the following to the web.config just below membership section:
<profile defaultProvider="UmbracoMemberProfileProvider" enabled="true">
<providers>
<clear />
<add name="UmbracoMemberProfileProvider" type="umbraco.providers.members.UmbracoProfileProvider, umbraco.providers" />
</providers>
<properties>
<clear />
<add name="address" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
</properties>
</profile>
Note that the name of the property is the same as the alias of the property you created on the member type in Umbraco.
Now you should be able to create a member, assign it to a member type and add a property value with the following code:
var member = Membership.CreateUser("mads.krohn", "tester", "[email protected]");
// Roles.AddUserToRole(member.UserName, "Standard group"); <-- You can also add your new member to a group you created in Umbraco
var profile = ProfileBase.Create(member.UserName);
profile["address"] = "test address";
profile.Save();
If you are planning to use more than one member type is appears you are out of luck, and instead need to begin implementing your own membership provider.
That however, is something I'm still strugling with and I haven't yet found out how to do it. I might make a new post asking for help on that one :)
Hope this will help you get things started.
As a follow up, Matt Brailsford answered my question regarding the implementation of a custom membership provider.
You might be able to use some of my code in conjunction with hes answer, the post is here
is working on a reply...