At the moment I have code to get the member ID (to store on a different database).
using umbraco.cms.businesslogic.member;
....
var memberID = Member.CurrentMemberId();
It's throwing a warning:
warning CS0618: 'umbraco.cms.businesslogic.member.Member' is obsolete:
'Use the MemberService and the Umbraco.Core.Models.Member models
instead'
But the MemberService is about CRUD operations and the Member class doesn't seem to do anything about the currently logged in member. I also found MembershipHelper.GetCurrentLoginStatus() but there's no ID on the returned data.
var x = new MemberService( new RepositoryFactory(), new MemberGroupService( new RepositoryFactory()) );
x. - what ever method you want.
Not 100% sure I newed up the member service properly as I have had no call to use it but I have used the UserSerivce as follows - var x = new UserService(new RepositoryFactory());
Just for reference in case anyone else is looking for the up-to-date reference (and being that I found this page from Googling umbraco memberservice) here the current (7.2+) version:
var myMemberService = new MemberService(new RepositoryFactory(), new MemberGroupService(new RepositoryFactory()));
var memberShipHelper = new MembershipHelper(UmbracoContext.Current);
member = myMemberService.GetById(memberShipHelper.GetCurrentMemberId());
Now it's even easier, in the surfaceController you can use just one line:
var member = ApplicationContext.Current.Services.MemberService.GetById(Members.GetCurrentMemberId());
If Members MembershipHElper isn't accessible:
var memberShipHelper = new MembershipHelper(UmbracoContext.Current);
var member = ApplicationContext.Current.Services.MemberService.GetById(memberShipHelper.GetCurrentMemberId());
How to get current member ID in Umbraco 7.1
At the moment I have code to get the member ID (to store on a different database).
It's throwing a warning:
But the MemberService is about CRUD operations and the Member class doesn't seem to do anything about the currently logged in member. I also found
MembershipHelper.GetCurrentLoginStatus()
but there's no ID on the returned data.Where should I go to get this information now?
try this:
var user = Membership.GetUser();
var userId = (int)user.ProviderUserKey;
So I should be dropping down to
System.Web.Security
- there's no Umbraco-y method?Yes, .NET Membership
Yep using the .Net membership is the way. You can impliment your own MembershipProvider which is usefull
Just create a class that impliments MembershipProvider.
You can also use the Umbraco Membership Service.
Charlie :)
http://our.umbraco.org/documentation/reference/management-v6/services/MemberService
Use the new API
using Umbraco.Core.Services;
using Umbraco.Core.Persistence;
var x = new MemberService( new RepositoryFactory(), new MemberGroupService( new RepositoryFactory()) );
x. - what ever method you want.
Not 100% sure I newed up the member service properly as I have had no call to use it but I have used the UserSerivce as follows - var x = new UserService(new RepositoryFactory());
Just for reference in case anyone else is looking for the up-to-date reference (and being that I found this page from Googling umbraco memberservice) here the current (7.2+) version:
Now it's even easier, in the surfaceController you can use just one line:
If Members MembershipHElper isn't accessible:
is working on a reply...