0

I've been through this tutorial which has been really helpful: http://www.blogfodder.co.uk/2011/12/31/umbraco-membership-templates

But VS is telling me that all my methods are obsolete. It tells me replacement methods to use for everything except setting the member type. Originally this was done in the Member.MakeNew method by passing MemberType as a parameter.

I've been to the Umbraco site and looked at the documentation on Membership, but there's a big note saying: "NOTE: This information is out of date and should be updated." http://our.umbraco.org/wiki/reference/api-cheatsheet/working-with-members

Does anyone know where I can find some updated code for creating members? And yes I have spent some time looking on google but all I can find is the older code.

Owen
  • 4,229
  • 5
  • 42
  • 50

3 Answers3

1

Umbraco uses .net membership since 4.5, or possibly even before this.

To create a user invoke the Membership.CreateUser method

Eric Herlitz
  • 25,354
  • 27
  • 113
  • 157
  • Yes but the only problem with .net membership is that there's no support for Umbraco MemberTypes. – Owen Oct 19 '12 at 09:11
1

I've managed to update my code to use .net membership without too much hassle.

Membership.CreateUser(...) replaces Member.MakeNew(...)

Roles.AddUserToRole(newMember,umbracoGroup) replaces newMember.AddGroup(umbracoGroup.Id).

But according to this post here http://our.umbraco.org/forum/developers/extending-umbraco/14614-Using-membership-provider-to-create-members-from-code, if you're using .net membership, it's only possible to have 1 MemberType by setting it in the web.config.

So hopefully I'll be able to stick to 1 MemberType, otherwise I'll be rolling my code back to use the Umbraco Membership classes.

Owen
  • 4,229
  • 5
  • 42
  • 50
  • 1
    AddGroup has been prematurely deprecated and isn't really considered obsolete since there's no replacement in the Member API yet. You can probably expect to see actual replacement methods in version 6.2 Umbraco. – Harry Jun 05 '13 at 13:01
1

If you are using umbraco 7 and some later versions of 6, you probably want to do this

IMember newMember = ApplicationContext.Current.Services.MemberService.CreateMember(emailAddress, emailAddress, memberName, memberTypeAlias);

or

IMember newMember = ApplicationContext.Current.Services.MemberService.CreateMemberWithIdentity(emailAddress, emailAddress, memberName, memberTypeAlias);

then

ApplicationContext.Current.Services.MemberService.Save(newMember);

to save the new member. Member must be saved before attempting to add to a group. To add to a group in umbraco 7 do

ApplicationContext.Current.Services.MemberService.AssignRole(newMember.Id, "Group Name");
Francis Benyah
  • 567
  • 7
  • 11