简体   繁体   English

获取当前登录到MS Dynamics CRM 2011 Online的用户的ID

[英]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? 有没有办法检索/识别当前登录到MS Dynamics CRM 2011 Online的用户?

What i'm trying to accomplish here is kind of like the facebook login except with MS Dynamics. 我要在这里完成的工作有点像Facebook登录,但MS Dynamics除外。 I need to somehow detect whether the user has logged into the MS Dynamics website. 我需要以某种方式检测用户是否已登录MS Dynamics网站。 If the user is logged into the MS Dynamics website, i'll have to grab the UserId and authenticate it with Kentico CMS. 如果用户登录到MS Dynamics网站,则必须获取UserId并使用Kentico CMS对其进行身份验证。

I've tried messing with the WhoAmIRequest, but unfortunately it needs a credential to properly execute. 我尝试过弄乱WhoAmIRequest,但不幸的是,它需要凭据才能正确执行。

Any help would be great! 任何帮助将是巨大的!

You can get the Currently Logged in User Id by 您可以通过以下方式获取当前登录的用户ID:

 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. 您可以从上下文获取用户ID。 Recheck this article . 重新检查这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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