简体   繁体   中英

Get Id of user currently logged into MS Dynamics CRM 2011 Online

Is there a way to retrieve/identify the user that is currently logged into MS Dynamics CRM 2011 Online?

What i'm trying to accomplish here is kind of like the facebook login except with MS Dynamics. I need to somehow detect whether the user has logged into the MS Dynamics website. If the user is logged into the MS Dynamics website, i'll have to grab the UserId and authenticate it with Kentico CMS.

I've tried messing with the WhoAmIRequest, but unfortunately it needs a credential to properly execute.

Any help would be great!

You can get the Currently Logged in User Id by

 WhoAmIRequest request = new WhoAmIRequest();
            WhoAmIResponse response = (WhoAmIResponse)Service.Execute(request);
            if (response != null)
                return response.UserId;

You can create a default service like:

ClientCredentials Credentials = new ClientCredentials();
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
//This URL needs to be updated to match the servername and Organization for the environment.


Uri OrganizationUri = new Uri("http://crm/XRMServices/2011/Organization.svc");

Uri HomeRealmUri = null;

//OrganizationServiceProxy serviceProxy; 

OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null)

IOrganizationService service = (IOrganizationService)serviceProxy;

You can get userid from context. Recheck this article .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM