More in this section

Forums / Developing with Sitefinity / Problem accessing user profiles and meta data

Problem accessing user profiles and meta data

9 posts, 2 answered
  1. Qezlot
    Qezlot avatar
    10 posts
    Registered:
    21 Apr 2010
    21 May 2010
    Link to this post
    Hi!
    I'm working with a system that uses Sitefinity (version 3.7 SP3 (or was it SP2?) Standard edition) for it's web site including the user administration. But it also communicates with an external database, outside of Sitefinity, where more user information is stored. When creating, updating or changing user details within the Sitefinity administration I hook up event handlers to the manageUsers object available inside the Admin_CmsAdmin_Users class (within the Users.aspx page) to listen to events like CreatedUser, UpdatedUser and DeletingUser. This all seams to work well.

    One problem I've encountered is with this code:
    DateTime activity = null;
    ProfileInfoCollection profileInfo = ProfileManager.FindProfilesByUserName
        (ProfileAuthenticationOption.All, manageUsers.UserName);
    if (profileInfo.Count > 0)
    {
        if (profileInfo[manageUsers.UserName] != null)
        {
            activity = profileInfo[manageUsers.UserName].LastActivityDate;
        }
    }

     
    This code does not find any user although the user specified in manageUsers.UserName do exist inside the Sitefinity database Telerik_Users and Telerik_UserMetaInfo tables.

    Although, if I instead use the following line to fetch the ProfileInfoCollection:

    ProfileInfoCollection profileInfo = ProfileManager.GetAllProfiles
        (ProfileAuthenticationOption.All);
    (Followed by the rest of the code from the above example).

    This code does work and finds the same profile. Is it something wrong with the FindProfilesByUserName-method?

    The next, bigger, problem is - HOW do I get the meta data for a specific user? When the administrator changes some meta information for a specific user I want to change some information in my external database depending on what was changed...

    Some pointers here would be very welcome!
    Kind regards
    Qezlot
    Sweden

     

     

  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    21 May 2010
    Link to this post
    Hi Ronny Thörnvall,

    Our profile provider (Telerik.DataAccess.AspnetProviders.TelerikProfileProvider) does not have a method FindProfilesByUserName which accepts only two arguments. The proper call should be like this:
    DateTime activity = new DateTime();
    int pageIndex = 0;
    int pageSize = 25;
    int totalRecords;
    ProfileInfoCollection profileInfo = ProfileManager.FindProfilesByUserName(ProfileAuthenticationOption.All, "admin", pageIndex, pageSize, out totalRecords);
    if (profileInfo.Count > 0)
    {
        if (profileInfo["admin"] != null)
        {
            activity = profileInfo["admin"].LastActivityDate;
        }
    }

    This method constructs a hash table, so the pageIndex is the page from which you want to start taking results, and the pageSize gives you maximum results per page.

    You can try another approach for getting the currently edited profile. You can try the bellow code:
    System.Web.Profile.ProfileBase userProfile = System.Web.Profile.ProfileBase.Create(manageUsers.UserName);
    //get specific property value from the profile object
    string userName = userProfile.GetPropertyValue("FirstName") as string;

    This gets profile meta data declared in the profile configuration section in web.config:
    <profile defaultProvider="Sitefinity">
        <providers>
            <clear />
            <add name="Sitefinity" connectionStringName="DefaultConnection" applicationName="/" type="Telerik.DataAccess.AspnetProviders.TelerikProfileProvider, Telerik.DataAccess" />
        </providers>
        <properties>
            <add name="FirstName" />
            <add name="LastName" />
            <add name="Position" />
            <add name="Photo_Hidden" />
            <add name="ChangePassword" defaultValue="True" type="Boolean" />
            <add name="Photo" defaultValue="~/Sitefinity/Common/Images/defaultavatar.gif" />
            <group name="InstantMessenger">
                <add name="IM_Type" />
                <add name="IM_Value" />
            </group>
            <group name="Phone">
                <add name="Value" />
                <add name="Type" />
            </group>
        </properties>
    </profile>


    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
  3. Qezlot
    Qezlot avatar
    10 posts
    Registered:
    21 Apr 2010
    21 May 2010
    Link to this post
    Hi Radoslav Georgiev - and thank you for your swift answer!

    I used the code example from:
    http://www.sitefinity.com/support/forums/sitefinity-3-x/developing-with-sitefinity/how-do-i-retrieve-all-user-profiles.aspx

    Which used the GetAllProfiles-method from the System.Web.Profile.ProfileManager class. It was there I also found the FindProfilesByUserName-method. It seams that I was using the wrong class only. :-) I will try to use the Telerik.DataAccess.AspnetProviders.TelerikProfileProvider class instead!

    So if I want to retrieve all profiles I just state 0 as pageIndex and some large int as pageSize? There is no overloaded method without these page parameters as in the System.Web.Profile counterpart?

    I tried your code for retrieving meta data for the specified user, it seams to work! Thank you!

    Kind regards
    Qezlot
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    21 May 2010
    Link to this post
    Hi Ronny Thörnvall,

    You can still use the same class as you did, just the second overload. This calls the .NET Profile manager which takes the default provider declared in the web.config (in this case the Telerik one). Note this method gets profiles based on user name. The page size only sets the size of pages - however it will get all users regardless of the page size.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Qezlot
    Qezlot avatar
    10 posts
    Registered:
    21 Apr 2010
    21 May 2010
    Link to this post
    Thank you again for your help!

    By the way - is there any online documentation about the object model within Telerik / Sitefinity? Information about methods, events, which parts you are supposed to extend or inherit from to solve different tasks?

    Have a nice weekend! :-)
    Kind regards
    Qezlot
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 May 2010
    Link to this post
    Hello Ronny Thörnvall,

    You could take a look at



    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Qezlot
    Qezlot avatar
    10 posts
    Registered:
    21 Apr 2010
    24 May 2010
    Link to this post
    Thank you for the links to different help pages, I knew about most of them already - but one problem is that when you search for help and articles about a specific problem, it's difficult to see what version of Sitefinity that the specific article is about and the code examples might not work on your current version... :-)

    About the help file about the architecture inside Sitefinity 3.7:
    I didn't get the links to work inside that help file, the .chm-file at: http://www.sitefinity.com/documents/SitefinityDeveloperManual_Aricles_v3_7.chm

    It only displays an error message about not beeing able to display the page at every meny link (I can only see the navigation menu about the help topics on the right side). I'm using a swedish operating system, could that affect the help file somehow?

    Kind regards,
    Qezlot
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 May 2010
    Link to this post
    Hello Qezlot,

    The problem is that your OS has blocked the chm preview. Right click on the file, properties and under the general tab there should be an option to unblock the preview.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
  9. Qezlot
    Qezlot avatar
    10 posts
    Registered:
    21 Apr 2010
    24 May 2010
    Link to this post
    Wonderful, that did the trick!

    Thank you for your quick replies!
    Kind regards
    Qezlot
Register for webinar
9 posts, 2 answered