Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 4 代表不同的用户行事/XrmServiceContext.CallerID_Asp.net Mvc 4_C# 4.0_Claims Based Identity_Dynamics Crm 2013 - Fatal编程技术网

Asp.net mvc 4 代表不同的用户行事/XrmServiceContext.CallerID

Asp.net mvc 4 代表不同的用户行事/XrmServiceContext.CallerID,asp.net-mvc-4,c#-4.0,claims-based-identity,dynamics-crm-2013,Asp.net Mvc 4,C# 4.0,Claims Based Identity,Dynamics Crm 2013,我已经为我的CRM 2013数据库使用svcuti.exe创建了一个XrmServiceContext,它工作得很好,我可以在MVC4应用程序中从CRM检索数据 我的网站正在使用ADFS2运行SSO,我可以通过以下方式检索访问用户身份: Microsoft.IdentityModel.Claims.IClaimsIdentity ci = Thread.CurrentPrincipal.Identity as Microsoft.IdentityModel.Claims.IClaimsIden

我已经为我的CRM 2013数据库使用svcuti.exe创建了一个
XrmServiceContext
,它工作得很好,我可以在MVC4应用程序中从CRM检索数据

我的网站正在使用ADFS2运行SSO,我可以通过以下方式检索访问用户身份:

Microsoft.IdentityModel.Claims.IClaimsIdentity ci =  Thread.CurrentPrincipal.Identity as Microsoft.IdentityModel.Claims.IClaimsIdentity;

var accountNameClaim = ci.Claims.Where(x => x.ClaimType.ToLower().EndsWith("windowsaccountname")).FirstOrDefault();
这给了我一些关于

string accountNameClaim=“firstname。lastname@domain.com“

使用此功能,我可以从CRM 2013
XrmServiceContext

var user = _serviceContext.SystemUserSet
                                        .Where( x=> x.DomainName == accountNameClaim)
                                        .Select(s => new UserInformationProxy()
                                          {
                                              Id = s.Id, // this is probably needed for impersonation
                                              FullName = s.FullName, 
                                              DomainName = s.DomainName
                                           })
                                         .FirstOrDefault();
现在,我想知道如何使用我的XRMServiceContext作为/模拟该用户进行所有后续的CRM查询


本页有一个指南,建议我需要在
OrganizationServiceContext
中设置一个名为
CallerID
的变量,我猜该变量包含在我的
XRMServiceContext
中。。但是我找不到它。

被调用的
属性不在
OrganizationServiceContext
上,而是在上下文使用的
OrganizationServiceProxy
上:

在构建上下文时,传递的是一个组织服务实例。在此之前,您需要设置
调用方ID

organizationService.CallerId = user.Id;
var _serviceContext = new OrganizationServiceContext(organizationService);

请注意,
CallerId
仅在
OrganizationServiceProxy
类型上可用,而在接口
IOOrganizationService
上不可用。我看不出您是如何获得organization服务的,但请确保它是OrganizationServiceProxy。

您最终找到了如何实现这一点吗?