Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 1288 posts 3921 karma points c-trib
    Nov 18, 2014 @ 22:54
    Dan
    0

    Get membershipHelper in API Controller

    Hi,

    I need to retrieve the username of the current logged in member (front-end) from within an API controller, using the new Service APIs (I can do it with the legacy APIs but would prefer not to use deprecated functionality). However, I'm struggling to get a context to be able to get a valid MembershipHelper.

    I've tried the following as per the documentation:

    var membershipHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current);
    

    ...but Umbraco.Web.UmbracoContext.Current errors, saying Umbraco.Web.UmbracoHelper does not contain a definition for 'Web'.

    Can anyone suggest how to get MembershipHelper correctly from in an API Controller?

    Thanks.

  • Vasia Vasia 49 posts 241 karma points
    Nov 18, 2014 @ 23:04
    Vasia Vasia
    0

    Hi,

    Try this 

    Umbraco.Core.ApplicationContext.Current.Services.MemberService

    http://our.umbraco.org/documentation/Reference/Management-v6/Services/MemberService

     

    Oleg

  • Dan 1288 posts 3921 karma points c-trib
    Nov 18, 2014 @ 23:24
    Dan
    0

    Thanks Oleg, but it's the MembershipHelper (http://our.umbraco.org/documentation/Reference/Querying/MemberShipHelper/) that I'm trying to get, rather than the MemberService.

    Regardless, Umbraco.Core.ApplicationContext.Current.Services.MemberService still errors ('Umbraco.Web.UmbracoHelper' does not contain a definition for 'Core' ...etc).

    Any other ideas?

  • Dan 1288 posts 3921 karma points c-trib
    Nov 19, 2014 @ 00:35
    Dan
    100

    I'd missed the fact that the class inherits from Umbraco.Web.WebApi.UmbracoApiController, so getting MembershipHelper is as simple as this:

    MembershipHelper membershipHelper = new MembershipHelper(UmbracoContext);
    

    ... from which I can now derive the current member username, using the memberService which is declared as follows:

    var memberService = ApplicationContext.Current.Services.MemberService;
    
  • Eduardo Sobrinho 18 posts 38 karma points
    Dec 03, 2014 @ 13:02
    Eduardo Sobrinho
    1

    Hi!

    I have the same problem. I soved as folow

    //obtem o usuario corrente...
    var memberService = ApplicationContext.Current.Services.MemberService;
    var memberHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current);
    IPublishedContent membro = memberHelper.GetCurrentMember();
    var m = memberService.GetById(membro.Id);

    (forgive my bad English)

Please Sign in or register to post replies

Write your reply to:

Draft