Copied to clipboard

Flag this post as spam?

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


  • Phill 115 posts 288 karma points
    Feb 02, 2013 @ 21:19
    Phill
    0

    Trying to get Member Name in 4.11.4 (MVC)

    Hi there,

    I'm trying t access the Umbraco Member name data. In source code for ViewMembers umbraco.cms.businesslogic.member object has a .Text field and this appears to be the users full name (or whatever you decided to put in there) However working in code using umbraco.cms.businesslogic.member is depreciated and I'm told to use asp.net membership. So how do I get access to this field? I've already added custom membership provider that inherits from ProfileBase so I can get access to the custom properties but for the life of me I can't figure out how to get this one field.

    I currently have:

    @foreach (var u in users)

    {

        var usr = Membership.GetUser(u);

        CustomMemberProfile profile = (CustomMemberProfile)System.Web.Profile.ProfileBase.Create(u);

    <div>@profile.CustomProperty</div>

    }

    This works, but neither Membership User nor Profile base have acces to this "Text" field where the user's name (not login name) is stored.

    Any help would be greatly appreciated!

    Regards,

    Phill

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 02, 2013 @ 22:12
    Jan Skovgaard
    0

    Hi Phill

    Perhaps you should try the code Sebastiaan posted in here http://our.umbraco.org/forum/developers/razor/19040-Working-with-members-and-Razor

    Hope this helps.

    /Jan

  • Phill 115 posts 288 karma points
    Feb 03, 2013 @ 01:38
    Phill
    0

    Hi Jan,

    That could potentially work, athought I've read in a number of places that umbraco.cms.businesslogic.member is obsolete and we should be using the .net Membership Proviers. The issue I have is I also want to list all members that are in a particular member group. I can get this list of users using:
    var users = Roles.GetUsersInRole("GroupName");
    however this returns a list of Username (or Logins) and nothing more. Then as you see in my code above I have to use a custom MemberProfile that inherits from ProfileBase to get the properties. The problem is I don't have any way of getting the umbraco Member id that is needed by var member = new Member(xxxx). How can I get a list of Member IDs for a specific group? If you look at the "how to" for membership providers it's 100% asp.net membership provider and nothing to do with Umbraco members. 

    It seems as if there was an umbraco Member system in place and then someone partially transitioned to .net membership provider but didn't finish the job and definitely didn't provide the documentation.

    So I greatly appreciate the tip but I'm still looking for a solution...

    Phill

     

  • Phill 115 posts 288 karma points
    Feb 03, 2013 @ 01:46
    Phill
    0

    Ok Jan, you got me in the right direction. Using var members = MemberGroup.GetByName("GroupName").GetMembers(); got me the list of members for a group and then from there I was able to get all the info I needed.

    I guess the only thing that's left me really confused is if I have to do everything with Umbraco Member then why is it marked as obsolete and why are many posters saying we should be doing things using asp.net membership provider. Doesn't make any sense at all. 

    p.s. I'm relatively new to Umbraco and this is my first project working with the member side of things, in case it wasn't obvious ;)

  • ID 27 posts 128 karma points
    Mar 07, 2013 @ 20:47
    ID
    0

    I'n curious if you did find a way to use the membership profile provider because i'm struggling with some alike.

    I have a SurfaceController for the login page and when a user logs in i want to redirect it to the page which is a property "home" of the member (Membertype content property)

    This works:

     

            [HttpPost]

            [ActionName("MemberLogin")]

            public ActionResult HandleMemberLogin(MemberLogin model)

            {

                if (!ModelState.IsValid)

                {

                    return CurrentUmbracoPage();

                }

     

                if (Membership.ValidateUser(model.Username, model.Password))

                {

                    FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);

                }

                else

                {

                    ModelState.AddModelError("Username", "Gebruikersnaam of wachtwoord is onjuist.");

                    return CurrentUmbracoPage();

                }

     

                Member member = Member.GetMemberByName(model.Username, true).FirstOrDefault();

                if (member != null)

                {

                    var propertyValue = member.getProperty("home").Value;

                    int pageId = Convert.ToInt32(propertyValue);

                    return RedirectToUmbracoPage(pageId);

                }

     

                return Redirect("/");

            }

     

     

    But how would someone rewrite this to use the ASP.NET Memberhip profile provider?

Please Sign in or register to post replies

Write your reply to:

Draft