|
Dieser Inhalt ist in Ihrer Sprache leider nicht verfügbar. Im Folgenden finden Sie die englische Version. |
CrmImpersonator Class (Sdk Assembly)
![]() |
Allows a block of code to execute under the process credentials instead of the running thread's identity.
The CrmImpersonator class implements the IDisposable interface. It exposes the following members.
| Constructor | Description |
| CrmImpersonator | Initializes a new instance of the CrmImpersonator class. |
| Instance Method | Description |
| Dispose | Releases the resources that are used by the CrmImpersonator instance. |
Remarks
This must be used inside a using statement. At the end of the using statement, execution will return to running under thread id.
Note When you are using this class, you must set the ownerid property for the entity when you use the Create method or Create message.
For more information about impersonation, see the MSDN documentation, located at http://msdn2.microsoft.com/en-us/library/aa376391.aspx.
Example
This shows how to use the CrmImpersonator class. For a complete example, see Authentication from an ASPX Page.
using (new CrmImpersonator())
{
CrmAuthenticationToken token;
if (offline == true)
{
token = new CrmAuthenticationToken();
}
else
{
token = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, orgname);
}
token.OrganizationName = orgname;
token.AuthenticationType = 0;
//Create the Service
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.CrmAuthenticationTokenValue = token;
service.Url = crmurl;
account account = new account();
account.name = "Offline Impersonator: " + DateTime.Now.TimeOfDay.ToString();
if (offline == false)
account.ownerid = new Owner("systemuser", token.CallerId);
service.Create(account);
}
Requirements
Namespace: Microsoft.Crm.Sdk
Assembly: Microsoft.Crm.Sdk.dll
See Also
Reference
© 2010 Microsoft Corporation. All rights reserved.
