Benachrichtigung

Dieser Inhalt ist in Ihrer Sprache leider nicht verfügbar. Im Folgenden finden Sie die englische Version.

Dieser Artikel wurde noch nicht bewertet - Dieses Thema bewerten.

CrmImpersonator Class (Sdk Assembly)

banner art

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.

ConstructorDescription
CrmImpersonatorInitializes a new instance of the CrmImpersonator class.

Instance MethodDescription
DisposeReleases 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.


Fanden Sie dies hilfreich?
(1500 verbleibende Zeichen)
Microsoft führt eine Onlineumfrage durch, um Ihre Meinung zur MSDN-Website zu erfahren. Wenn Sie sich zur Teilnahme entscheiden, wird Ihnen die Onlineumfrage angezeigt, sobald Sie die MSDN-Website verlassen.

Möchten Sie an der Umfrage teilnehmen?