locked
How to change MSCRM 4.0 code using the late bound and as per crm 2013 SDK. RRS feed

  • Question

  • HI All,

          Can anybody help me in changing the below code.

    the below code is from MSCRM 4.0 code

     using (new Microsoft.Crm.Sdk.CrmImpersonator())
            {
                Microsoft.Crm.Sdk.CrmAuthenticationToken token;
                if(!offline)
                    token = Microsoft.Crm.Sdk.CrmAuthenticationToken.ExtractCrmAuthenticationToken(context, organisation);
                else
                    token = new Microsoft.Crm.Sdk.CrmAuthenticationToken();
                token.OrganizationName = organisation;
                //token.AuthenticationType = 0;
                Microsoft.Crm.SdkTypeProxy.CrmService service = new Microsoft.Crm.SdkTypeProxy.CrmService();
                service.CrmAuthenticationTokenValue = token;
                service.Credentials = CredentialCache.DefaultCredentials;
                return token.CallerId.ToString();
            }

    Will appreciate if anybody give the alternate for this.

    Friday, October 23, 2015 12:10 PM

All replies

  • Hello,

    Seems that you're trying to implement ASP.Net application. The thing is that ASP.Net is not supported anymore for CRM 2011/2013. I would suggest to switch to Html/Css/JS webresources instead of trying to upgrade ASP.Net app.


    Dynamics CRM MVP
    My blog

    Friday, October 23, 2015 2:12 PM
    Moderator
  • Please refer example MSDN article for this, this explain how to imporsonate in CRM 2011 (also in 2013 and 2015)

    https://msdn.microsoft.com/en-us/library/gg309629(v=crm.5).aspx

    Following is details on CRM 2011 CRM SDK for updating ISV code from CRM 4.0

    ----------------------------------------------------------------------------------------------------------------------------

    In Microsoft Dynamics CRM 4, ISV’s could create and integrate ASPX Web pages
    with the Web application. These Web pages could support single sign-on (SSO) or
    could perform operations on behalf of the user through impersonation. In
    Microsoft Dynamics CRM 2011, calling the Microsoft Dynamics CRM 2011 Web
    services from the <crmwebroot>\<notlocalizable xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">ISV</notlocalizable>
     folder is no longer supported. The ISV folder is officially deprecated.

    When upgrading to Microsoft Dynamics CRM 2011, if your existing Web pages
    meet the following criteria, they will continue to work.


    • The ASPX Web pages are installed under the
      <crmwebroot>\<notlocalizable xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">ISV</notlocalizable>
      folder.
    • The Web pages use the 2007 ASMX Web service
      endpoint.
    • The Web page code uses the CrmImpersonator class for
      switching the thread context or the
      CrmAuthenticationToken.ExtractCrmAuthenticationToken method to get the
      UserId.

    Sample code for a Microsoft Dynamics CRM 4.0 ISV Web application that is
    compatible with Microsoft Dynamics CRM 2011 can be found in the
    SDK\SampleCode\CS\GeneralProgramming\Authentication\IFDBackCompat
    folder of the SDK download.


    Guidelines for Developing New Code

    <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">

    When developing new code, the recommendation is to use the Web
    resources feature of Microsoft Dynamics CRM 2011. For scenarios that will not be
    satisfied by the Web resources feature, create your Web application in its own
    application pool with its own <notlocalizable xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">web.config</notlocalizable>.
    For this discussion, this application will be referred to as the ISV Web
    application.

    </content><sections xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">

    Single Sign-On

    <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">

    For on-premises (AD) only scenarios, use integrated authentication.
    For an Internet-facing deployment (IFD), on-premises with claims, or Microsoft
    Dynamics CRM Online scenarios, make the ISV Web application a relying party to
    the Secure Token Service (STS) that Microsoft Dynamics CRM is configured
    against.

    </content>

    Impersonation

    <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">

    When the user navigates to the ISV Web page, the page is presented
    with a token by STS that has the end user Universal Principal Name (UPN). The
    ISV Web page can retrieve the Microsoft Dynamics CRM UserId using a Web
    service call, by matching against the UserName UPN. If the Web page
    has ActOnBehalfOf privilege, it can then do impersonation of the user
    against the Web service. There is no need for the ISV Web page application pool
    account to be a member of the PrivUserGroup group.

    </content>

    Same Site of Origin Policy

    <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">

    For same site of origin policy requirements where ISV Web pages need
    to manipulate the Document Object Model (DOM) of the container Microsoft
    Dynamics CRM page, you need to host the ISV Web application on the same server
    or under a sub-domain. However, this will not work for Microsoft Dynamics CRM
    Online. Hosting the ISV Web application inside the Microsoft Dynamics CRM site
    virtual directory or under the ISV folder is not supported. Alternately, Web
    resources are a way to mitigate this issue because they are delivered from the
    Microsoft Dynamics CRM server for all deployment types.

    </content>

    Relative Path Concerns

    <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">

    When referring to the ISV Web application URLs from Microsoft
    Dynamics CRM Web application ribbons or the sitemap, the concern was that the
    URL is not relative. The recommended solution is to provide JavaScript that
    obtains the URL from a configuration entity that will be populated as a post
    solution install action based on the tenant where it was
    installed.

    </content>
    </sections>

    -----------------------------------------------------------------------------------------------------------------------------

    Hope this helps..


    MayankP
    My Blog
    Follow Me on Twitter

    Saturday, October 24, 2015 11:02 AM
    Answerer