CallerImpersonationScope Class

 

Updated: November 29, 2016

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

Identifies a user as the owner of all data changes made by calls to a Web service.

Namespace:   Microsoft.Xrm.Sdk
Assembly:  Microsoft.Xrm.Sdk (in Microsoft.Xrm.Sdk.dll)

SystemObject
  Microsoft.Xrm.SdkCallerImpersonationScope

No code example is currently available or this language may not be supported.

NameDescription
System_CAPS_pubmethodCallerImpersonationScope

Initializes a new instance of theCallerImpersonationScope class.

NameDescription
System_CAPS_pubmethodDispose

Disposes the CallerImpersonationScope object.

System_CAPS_pubmethodEquals

(Inherited from Object.)

System_CAPS_pubmethodGetHashCode

(Inherited from Object.)

System_CAPS_pubmethodGetType

(Inherited from Object.)

System_CAPS_pubmethodToString

(Inherited from Object.)

The specified user does not have to be the same user that instantiated the service. When the CallerImpersonationScope object goes out of scope and is disposed, calls to the service are owned by the original user that instantiated the service.


using (new CallerImpersonationScope(service, userId))
{
   // Display information about the logged on user.
   Guid effectiveUserId = ((WhoAmIResponse)service.Execute(new WhoAmIRequest())).UserId;
   SystemUser systemUser = (SystemUser)service.Retrieve("systemuser", effectiveUserId, 
       new ColumnSet(new string[] {"firstname", "lastname"}));
   Console.WriteLine("Logged on user is {0} {1}.", systemUser.FirstName, systemUser.LastName);
}

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright

Community Additions

Show: