Copied to clipboard

Flag this post as spam?

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


  • Dmitrij Jazel 86 posts 179 karma points
    Feb 10, 2013 @ 18:13
    Dmitrij Jazel
    0

    Working with members in C#

    Hej Guys,

    This one should be quite easy...

    I just downloaded newest umbraco 6.0 and playing arround with it...

    So what I am having trouble with:

    Pull out a member from all members by UserName.

    Than access it's properties (f.ex. Name)

    Than I want to add some other properties (like age, currentLocation and stuff like that...)...

     

    For now I have this...

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Security;
    
    using umbraco.cms.businesslogic.member;
    
    namespace members_test
    {
        public partial class PublicIndex : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                string mbr_UserName = "pikachiu"
                MembershipUser member = System.Web.Security.Membership.GetUser(mbr_UserName);
                string email = member.Email; // <-- am getting null here!?
    
                //var member =  umbraco.cms.businesslogic.member.Member.GetMemberFromLoginName(mbr_UserName); <!-- this one is considered Obsolete!?...       
    } } }

    But for some reason I am getting null pointer exception while accessing MembershipUser

    And another Member.getMemberFromLoginName() method says it's obsolete... so not sure what to do here :(

     

    //Dmitrij

     

     

  • Dmitrij Jazel 86 posts 179 karma points
    Feb 10, 2013 @ 18:18
    Dmitrij Jazel
    0

    Edit:

    in the line string mbr_UserName ="pikachiu"

    I have ";" corrected... string mbr_UserName ="pikachiu";

  • Charles Afford 1163 posts 1709 karma points
    Feb 10, 2013 @ 20:13
    Charles Afford
    0

    Hey Dmitrij,

    Have you checked that a member with the username called 'pikachiu' has been setup in Umbraco.

     

    string mbr_Email ="emailAddressYouSetupForTheUser"

    Also what do you get from: MembershipUser member =System.Web.Security.Membership.GetUserNameByEmail(mbr_Email);

    I am presuming you are in the umbraco context and hitting the breakpoint?

    Charlie. :)

     

     

  • Dmitrij Jazel 86 posts 179 karma points
    Feb 10, 2013 @ 21:33
    Dmitrij Jazel
    0

    Hej Charles :-)

    Well yes, I have a Member with UserName "pikachiu".

    Regarding

    MembershipUser member =System.Web.Security.Membership.GetUserNameByEmail(mbr_Email);

    you suggest here.

    I am getting the same, I see that I am getting the instance of the member, the problem was that I could not call it's username (or in your case email - got the same issue) ... It needed to have .toString(); method, So when I called toString() on it, it actually works, but I wounder why it needs it, cause ".Email" is of type "string". So it works with .toString() for now...

     

    But than here comes another part of the question - if I choose this approach how can I manage Member properties (like Age, Job, Phone for example...).

     

    Thanks for help :-)

     

    //Dmitrij

  • Charles Afford 1163 posts 1709 karma points
    Feb 10, 2013 @ 21:48
    Charles Afford
    0

    Ah that would atcually make sense 

    If instanciated a member and then called the GetUserNameByEmail method you should not have to cast.

    You second question is the same problem i am going to come up against next week. There are quite alot of forum posts about it. There does not seem to be a problem manageing the propertys. Create some auto properties Age Job Phone ect and then there should be be a method of the member to assign these. The problem appears to be saving these values back to the database.

    Take a look at this post:

    http://our.umbraco.org/forum/developers/api-questions/12348-member-profile-problem-45x?p=0#comment76619

    Please let me know if you get a solution working :D Thanks.  Charlie :)


  • Dmitrij Jazel 86 posts 179 karma points
    Feb 10, 2013 @ 22:10
    Dmitrij Jazel
    0

    Hehe :-)

    I sure will try, I still look forward to discuss this toppic here until I get it done in the way how it's REALLY supposed to be done! :-)

    For now I am sticking to this approach: http://our.umbraco.org/wiki/how-tos/membership-providers

    And than I intent to use something called "user profiles" (look in the buttom of the page in that link).

    But at the same time I found this [http://www.aaron-powell.com/umbraco-members-profiles] thing here, lots of people discussed here

    But the problem is - I don't see the way how can I edit users in from Member administration in Umbraco, cause there are only "username" and email password etc... but if user has a profile picture or googleLocation f.ex... how do I find a way to do that? Is that possible to do through admin pannel, or I have to write my own umbraco section to manage that?

    Have a great evening :-)

    //Dmitrij

  • Charles Afford 1163 posts 1709 karma points
    Feb 10, 2013 @ 22:52
    Charles Afford
    0

    When you are refering to users?  Do you mean members?  

    Users: People who can use umbraco

    Members: People who can log into the site.

    In Umbraco you can add custom properties to a member, as you would with a datatype.  Then you can interact with these using the member provider.  Having never done this before its going to be something new for me as well.  Will take a look at your resounces.  Thanks.  Charlei :)

  • Charles Afford 1163 posts 1709 karma points
    Feb 10, 2013 @ 22:53
    Charles Afford
    0

    Yea that web config way seems valid.  I think i have read some people have had trouble with saving that information to the database.  But the webconfig way is how i am going to approach it i think :)

  • Charles Afford 1163 posts 1709 karma points
    Feb 10, 2013 @ 22:57
    Charles Afford
    0

    That second link seems a bit of a suspect implimentation.  I just feel there must be an easier way to do it :).  Let me know what you find.  Have a great evening too :)  Charlie :)

  • Dmitrij Jazel 86 posts 179 karma points
    Feb 10, 2013 @ 23:08
    Dmitrij Jazel
    0

    Hej again charles,

    By using "users" I meant Members, and I totally agree with your terminology :-)

    Cause the whole thing here is all about members :-)

    well aniways... yea sure, I am still sticking to first approach (the correct one) but I am keeping another one just in case.

    Let me know if you have some progress aswell :)))

    Cheers,

    //Dmitrij

  • Charles Afford 1163 posts 1709 karma points
    Feb 11, 2013 @ 22:51
    Charles Afford
    0

    Replied to this in the other topic :)

  • Dmitrij Jazel 86 posts 179 karma points
    Feb 11, 2013 @ 22:59
    Dmitrij Jazel
    0

    Hej Charls,

    yes I see now... thanks for help mate :-)))

    I will now try find some time and try actually going step by step in that article yous send me. (we both read last time)

    Only difference now I really understand it... :-)

    If any more problems will apear, I will let you know in that another post.

    Thanks alot for help so far!!! :-)))

     

    Regards,

    Dmitrij

  • Charles Afford 1163 posts 1709 karma points
    Feb 12, 2013 @ 21:35
    Charles Afford
    0

    No problem :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies