Copied to clipboard

Flag this post as spam?

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

  • Jeroen Breuer 4902 posts 12234 karma points MVP 3x admin c-trib
    Nov 04, 2015 @ 16:55
    Jeroen Breuer

    Get member email from IPublishedContent


    I'm using the Umbraco MemberShipHelper. The helper has 2 methods:

    GetCurrentMember() GetCurrentMemberProfileModel()

    The first method returns an IPublishedContent. How can I get the email of a member from that? The property is available on the ProfileModel that GetCurrentMemberProfileModel() returns, but I prefer not to use 2 methods to get the current member.


  • Kevin Jump 2195 posts 14010 karma points MVP 6x c-trib
    Nov 04, 2015 @ 17:02
    Kevin Jump


    I had to write some code to do this a few versions back (v7.2) and then you couldn't get it from the IPublishedContent model.

    there is an issue somewhere so i am not sure if it got fixed in later versions - but i ended up making the member dynamic

    var email member.AsDynamic().Email;

    bit of a hack but it works.

  • Ravi Motha 290 posts 500 karma points MVP 6x c-trib
    Nov 04, 2015 @ 17:13
    Ravi Motha


    I've used the membership helper in this way and can return any of the properties

    var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current);
    var myUser = memberShipHelper.GetCurrentMember();


    I'm using a 7.2.x and I've had no problems with it

  • Jeroen Breuer 4902 posts 12234 karma points MVP 3x admin c-trib
    Nov 04, 2015 @ 18:19
    Jeroen Breuer

    Thanks for the tips. Will try myUser.GetProperty("Email").Value. The reason I didn't try it is because email isn't a property set on the member type. When the models builder generated a strongly typed model it also didn't contain an email property.


  • Anders Bjerner 476 posts 2885 karma points MVP 6x admin c-trib
    Nov 04, 2015 @ 20:24
    Anders Bjerner

    Hi Jeroen,

    When you reference a member by IPublishedContent it is really an instance of MemberPublishedContent. If you cast to this type, you will have acces to an email property (as well as other member-only properties):

        IPublishedContent content = Umbraco.TypedMember(memberId);
        MemberPublishedContent member = (MemberPublishedContent) content;
  • Tobbe 81 posts 387 karma points c-trib
    Jan 05, 2018 @ 09:14

    When I try to do this I get this error (using umbraco 7.7.2):

    Unable to cast object of type 'Umbraco.Web.PublishedContentModels.Member' to type 'Umbraco.Web.PublishedCache.MemberPublishedContent'.

    Getting the same error if I try to use ApplicationContext.Current.Services.MemberService.GetById(memberId)

  • Jeroen Breuer 4902 posts 12234 karma points MVP 3x admin c-trib
    Nov 05, 2015 @ 10:38
    Jeroen Breuer

    Since I'm using the ModelsBuilder I don't get a MemberPublishedContent back, but the generated model which doesn't have the Email property. I fixed it with this code:

    public partial class Member
        public string Email
                return this.GetPropertyValue<string>("Email");


  • Sean Håkansson 64 posts 190 karma points
    Dec 11, 2017 @ 14:14
    Sean HÃ¥kansson

    Sorry for the newb question and more than a year later :) But where would I put this? (Not in the auto-generated file I'm guessing)

  • Kevin Jump 2195 posts 14010 karma points MVP 6x c-trib
    Dec 11, 2017 @ 14:23
    Kevin Jump


    You can put this in it's own file in somewhere such as the App_Code folder (you might need to create this).

    the generated classes are marked as partial, which means you can create other partial classes with the same name across your project and they are turned into one class as compile/run time.

  • Richard Eyres 98 posts 580 karma points
    Oct 25, 2016 @ 14:05
    Richard Eyres

    Thanks Jeroen. This was the exact same situation i found myself in. Your reply just saved me a little time. Thank you.

  • Chris 12 posts 84 karma points
    Oct 24, 2018 @ 14:39

    I have found you can get the email dynamically, but not typed:

Please Sign in or register to post replies

Write your reply to: