More in this section

Forums / Developing with Sitefinity / Search for Users by Metadata

Search for Users by Metadata

4 posts, 0 answered
  1. JohnGassman
    JohnGassman avatar
    18 posts
    Registered:
    03 Nov 2006
    25 Aug 2009
    Link to this post
    Hello,

    We are creating some custom registration and login controls and we need to be able to lookup users based on metadata (as specified in the <profile><properties> section of web.config, values stored in the telerik_UserMetaData table). For example, we have added an ID metadata field and would like to search for a user with this ID to verify that no users exist with the same value for ID.

    Are there any existing methods that would enable us to retrieve user(s) by an arbitrary profile property value? I have seen methods to find users by Email or Username, but those fields are in the main telerik_Users table, not the telerik_UserMetaData table, so I don't think they would help me get any closer to a custom method for doing this.

    Thanks and Regards,
    John
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Aug 2009
    Link to this post
    Hello JohnGassman,

    You can use ProfileBase or ProfileCommon classes. Sample code:

    string userName = UserManager.GetCurrentUserName(); 
    ProfileBase profiler = ProfileBase.Create(userName); 
    profiler.GetPropertyValue("Organization"); 

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. JohnGassman
    JohnGassman avatar
    18 posts
    Registered:
    03 Nov 2006
    25 Aug 2009
    Link to this post

    Ivan,

    Thanks for the information, but I think you are describing how to access metadata for a user - we would like to find users from a metadata value. Something like the FindUsersByEmail method of the UserManager object. But, we would like to FindUsersByPhoneNumber, or FindUsersByMetaData(PropertyName, PropertyValue). Is there any existing code in SItefinity that finds users by any of the property/value information in telerik_UserMetaData table?

    Thanks again,

    John

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    26 Aug 2009
    Link to this post
    Hi JohnGassman,

    If you take a look at Membership Methods you will see that you can only use FindUsersByEmail and FindUsersByName. Possible solution could be using ProfileInfoCpllection but this calls the database every time so that you will have a problem with the performance.

    ProfileInfoCollection profileInfo = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All); 
            foreach(ProfileInfo profile in profileInfo)  
            { 
                
            } 


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered