Copied to clipboard

Flag this post as spam?

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


  • Enrique Gutierrez 7 posts 29 karma points
    Mar 18, 2010 @ 01:52
    Enrique Gutierrez
    0

    Retrieving all Member Groups for Logged In User

    I'm working in Umbraco 4.0.2 (I believe) and no little to nothing about XSLT; thus - I've been attempting to create a custom user control in C# which retrieves the Member Groups (in general) and/or specifically retrieves the Member Groups of a speficied (logged in) user.

    The code I have come up with is ... pretty much nothing, so I've taken it back to "int i = CurrentMemberId();" and started hunting for a potential solution that someone else may have done elsewhere. I've found nothing & hence the post.

  • skiltz 501 posts 701 karma points
    Mar 18, 2010 @ 02:24
    skiltz
    1

    In .umbracoyou can use asp.net mebership stuff....so you should be able to get all roles for a user like Roles.GetRolesForUser(User.Identity.Name)

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Mar 18, 2010 @ 08:39
    Casey Neehouse
    1

    This is a method for XSLT that I wrote a long long time ago..  Should get you started.

           public static XPathNodeIterator GetMemberGroupsForMember(int memberId)
    {
    Member m = new Member(memberId);
    XmlDocument d = new XmlDocument();
    XmlElement g = d.CreateElement("groups");

    foreach (int i in m.Groups.Keys)
    {
    MemberGroup mg = new MemberGroup(i);
    XmlElement e = d.CreateElement("group");
    XmlAttribute a = d.CreateAttribute("id");
    a.Value = mg.Id.ToString();
    e.Attributes.Append(a);
    e.InnerText = mg.Text;
    g.AppendChild(e);
    }
    d.AppendChild(g);
    return d.CreateNavigator().Select("/groups");
    }
  • Enrique Gutierrez 7 posts 29 karma points
    Mar 19, 2010 @ 10:59
    Enrique Gutierrez
    0

    For reference :

    if (HttpContext.Current.User.Identity.IsAuthenticated)
    {
    int memberId = CurrentMemberId();
    string[] roles = Roles.GetRolesForUser(HttpContext.Current.User.Identity.Name);

    for (int i = 0; i < roles.Length; i++)
    {
    txtLoggedIn.Text += roles[i];
    }

    }
    else
    {
    txtLoggedIn.Text = "Please Log in";
    }

    "Roles" actually got me exactly what I needed. I'm throwing in a snippet that kicks out Member Group names for grins in case someone needs it. Very good start for me, so thank you guys for the input! It helped immensly.

     

Please Sign in or register to post replies

Write your reply to:

Draft