Best Practices for Working with Custom ASP.NET Pages and Microsoft Dynamics CRM 2011

When it comes to developing custom ASP.NET pages that need to integrate with Microsoft Dynamics CRM 2011, Microsoft recommends hosting them as a separate web application outside of the CRM web application, instead of inside the ISV folder or a virtual directory.

This means these pages will have a base URL that is different to the CRM’s. For example: http://crm.company.com, and http://crmcustompages.company.com.

Whilst you can still display these pages in IFRAMES inside CRM forms, you will run into issues when trying to access the HTML DOM of the CRM form from a custom page, and vice versa due to JavaScript’s cross-domain restriction.

You can overcome this issue by declaring the same “document.domain” in the JavaScript in both the CRM forms and the custom pages. In the context of the example above, it would be: document.domain = “company.com”.

Unfortunately, the problem doesn’t stop there. You will notice that when you do this, it breaks some of the Ribbon functionalities (e.g. can’t add child records), the calendar date picker, etc.

Hence, I believe that the best practice would be for the website to be hosted as a separate web application under the CRM web application. It is still a separate web application, and both CRM and the custom website now share the same base URL – http://crm.company.com.

A few extra steps to get the custom pages working in the web application inside the CRM:

  • Copy the following DLL files to the bin folder of the website:

  • Add the section marked in red below to the website’s web.config.
<!--?xml version="1.0" encoding="UTF-8"?>
 <configuration>
   <configSections>
      <remove name="crm.authentication" />
    </configSections>
    <appSettings>
     <clear />
 ...

Problem solved.

I have been using this approach for over a few months now, and everything is going great and problem-free. I do strongly believe that this is a good compromise between the strictly supported approach and getting the JavaScript to be able to talk between the CRM forms and custom pages.

Advertisements

8 thoughts on “Best Practices for Working with Custom ASP.NET Pages and Microsoft Dynamics CRM 2011

  1. Hi, how I want to follow your method, of hosting Custom WebPages as a separate web application under the CRM web application. But I dont know how to do it,
    can you provide step by step process for that.
    Thanks

  2. Hi, I create one web application under CRMwebsite, but it returns 404 – File or directory not found.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s