locked
Get currently logged in user using C# for CRM Dynamics 2011 RRS feed

  • Question

  • Hello,

    I would like to ask on how to get the id of the currently logged in user using c# for CRM Dynamics 2011.

    Appreciate any response..

    Thanks and regards,

    Honey

    Monday, October 28, 2013 5:46 AM

Answers

  • Answered here - use the executionContext.UserId

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful. Michael Mayo

    • Marked as answer by Honey Dulatre Wednesday, August 13, 2014 6:17 AM
    Friday, November 1, 2013 8:30 PM

All replies

  • Hello,

    Please check the following link

    http://www.powerobjects.com/blog/2009/04/09/current-user-in-crm/

    http://mileyja.blogspot.com/2011/06/get-current-user-id-and-organization-id.html


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
    Vikram !


    • Edited by _Vikram Monday, October 28, 2013 6:09 AM
    • Proposed as answer by HIMBAPModerator Monday, October 28, 2013 6:19 AM
    Monday, October 28, 2013 6:08 AM
  • Hello,

    you can use WhoAMIRequest for this check: http://mileyja.blogspot.in/2011/06/get-current-user-id-and-organization-id.html

    http://www.powerobjects.com/blog/2009/04/09/current-user-in-crm/

    HTH


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Monday, October 28, 2013 6:18 AM
    Moderator
  • Hi,

    i have used this code but it returns an incorrect id

                        WhoAmIRequest whoReq = new WhoAmIRequest();
                        WhoAmIResponse whoResp = (WhoAmIResponse)service.Execute(whoReq);
                        Guid userid = whoResp.UserId;

    when i tried below code in which i found in one of the blogs you presented, i am getting an invalid code.

    Guid userGuid;

    if(Request.LogonUserIdentity.IsAuthenticated == true)

    {

        WhoAmIRequest userRequest = new Microsoft.Crm.SdkTypeProxy.WhoAmIRequest();

        WhoAmIResponse user = (Microsoft.Crm.SdkTypeProxy.WhoAmIResponse)objCrmService.Execute(userRequest);

        userGuid = user.UserId;

    }

    else //ifd

    {

          userGuid = new Guid(Context.User.Identity.Name);

    }

    Is there any parameters that i should add or reference that i should add as well?

    Thanks in advance for the support.

    regards,

    Honey

    Monday, October 28, 2013 6:20 AM
  • No,

    You don't need to pass any additional parameter you should get currectly loggedin system user with this request.


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Monday, October 28, 2013 6:49 AM
    Moderator
  • Hi Honey Dulatre,

    You can get user id by using below code.         

     Guid userid = ((WhoAmIResponse)_objService.Execute(new WhoAmIRequest())).UserId;
     

    -----------------------------------------

    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful" Thank you, Sorde

    • Proposed as answer by Suresh Sorde Tuesday, October 29, 2013 5:35 AM
    Tuesday, October 29, 2013 5:35 AM
  • You could get an incorrect value if you are using WhoAmIRequest from a plugin which is set up with impersonation. Could that be the case?
    Tuesday, October 29, 2013 8:26 AM
  • Sorry for the late response as i focused on another issue im experiencing. i'll try the one you send above and we'll send an update if that resolve's the issue. thank you so much for the help!

     regards, 

    Honey

    Thursday, October 31, 2013 8:51 AM
  • Answered here - use the executionContext.UserId

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful. Michael Mayo

    • Marked as answer by Honey Dulatre Wednesday, August 13, 2014 6:17 AM
    Friday, November 1, 2013 8:30 PM
  • Hi Michael,

    I used the context.UserId to get the user id.

    Thanks and regards,

    Honey

    Wednesday, August 13, 2014 6:17 AM