Copied to clipboard

Flag this post as spam?

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


  • Thomas Stock 40 posts 70 karma points
    Nov 02, 2010 @ 14:38
    Thomas Stock
    0

    Retrieve a member's profile by username

    Hi,

    Is there a way to retrieve a member's profile by username?

    Normally a MembershipProvider has a method like this:

    var existingProfile = ProfileManager.FindProfilesByUserName(ProfileAuthenticationOption.All, memberData.UserName);

    But I see in the Umbraco sourcecode that this method is not supported:

            public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) {
                throw new NotSupportedException();
            }

    Is there a specific reason why this method is not supported?

    Is there an alternative?

    Thanks.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Dec 10, 2010 @ 13:58
    Lee Kelleher
    0

    Hi Thomas,

    As far as I'm aware, the only methods of the UmbracoProfileProvider that are implemented are the "GetPropertyValues" and "SetPropertyValues".  All the other methods throw a NotSupportedException.

    In this case, you'll need to roll your own ProfileProvider (that inherits from the UmbracoProfileProvider).

    Also, there is a blog post about Member Profiles here: http://aaron-powell.com/umbraco-members-profiles

    Cheers, Lee,

  • Thomas Stock 40 posts 70 karma points
    Dec 10, 2010 @ 14:09
    Thomas Stock
    0

    Thanks Lee for taking the time to answer my questions.

    I didn't think about inheriting from the UmbracoProfileProvider class, that would have been a cleaner solution than what I came up with.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Dec 10, 2010 @ 14:19
    Lee Kelleher
    0

    Hi Thomas, you're welcome.

    I've been doing some work with the MembershipProviders recently, although I haven't used the ProfileProvider yet - I ended up going direct to the Umbraco members API (even though most of them are marked as obsolete).  Like you say, its often the best solution you can come up with at the time! :-)

    Cheers, Lee.

  • Thomas Stock 40 posts 70 karma points
    Dec 10, 2010 @ 14:29
    Thomas Stock
    2

    Indeed, I did the same.

    Straight from my project:

            public static MemberData GetProfile(string username, MemberData memberData)
            {
                AssertMemberExists(username);

                //Umbraco says this method is obsolete, but it is needed to retrieve the profile properties from a non-logged in user..
                var m = Member.GetMemberFromLoginName(username);

                return MemberPropertyManager.GetProfileProperties(m, memberData);
            }

    I have a MemberData class that I inherit from for each member type, marking properties with [MemberProperty(Alias="property alias")].
    In my MemberPropertyManager.GetProfileProperties I use reflection to get the property aliases and retrieve them the using the Member API.

    I'll just leave this here for future googlers.

Please Sign in or register to post replies

Write your reply to:

Draft