Forums

Forums / Developing Portals / How to get contact/account id of current user in code behind ?

How to get contact/account id of current user in code behind ?

Thread is closed for posting
4 posts, 1 answered
  1. quanganh
    quanganh avatar
    33 posts
    Registered:
    16 Jun 2016
    28 Jul 2016
    Link to this post
    Hello all,

    Currently I have master page which is created in c#, I want to get contact/account id of current user. Is is possible to do this ?

    Many thanks,
    Quang Anh
  2. Missing user
    Missing user avatar
    09 Aug 2016 in reply to quanganh
    Link to this post
    Hi Quang,

    I emailed the sample code file to Julien, and he has confirmed that you were able build the required functionality.  Please let us know if you have any further question.

    Thanks
    Syed
  3. matthew.edwards@dsr.wa.gov.au
    matthew.edwards@dsr.wa.gov.au avatar
    1 posts
    Registered:
    25 Nov 2015
    05 Oct 2016
    Link to this post
    Hi,

    I would very much love to know how this is done also. We are trying to tie sitinfinty portal logins to CRM to restrict search data.

    Cheers,

    MJ
  4. kuba
    kuba avatar
    8 posts
    Registered:
    21 Apr 2016
    Answered
    25 Oct 2016 in reply to matthew.edwards@dsr.wa.gov.au
    Link to this post
    Not sure if this is the best way, but this is what I worked out should anyone else find it useful:

    private string GetUserCrmContactId()
    {
    string crmGuid = string.Empty;
    try
    {
    Guid userId = ClaimsManager.GetCurrentUserId();
    UserProfileManager profileManager = UserProfileManager.GetManager();
    UserProfile userProfile = profileManager.GetUserProfile(userId, typeof(SitefinityProfile).FullName);
    crmGuid = userProfile.GetValue("CRMContactId").ToString();
    }
    catch (Exception ee)
    {
    // do something with the error
    }
    return crmGuid;
    }
4 posts, 1 answered