CRM 4.0 Deployment Problem – web.config cannot be loaded properly

Today I developed an application to be deployed in ISV. However as per request I couldn’t use the default organization,
so I need to change the url from:
http://(server-name)/ISV/(app-name)
to:
http://(server-name)/(organization-name)/ISV/(app-name)

The problem is my current web.config couldn’t be loaded properly. I got empty configuration even I use existing configuration from other project that use the same CRM.
After a chat with my work mate, he come accoss to Janne Mattila’s blog and I found the solution.

That’s a relief, yet not the end of the problem. I have a project that contains all CRM functions there. The solution above only applicable if I use those functions in one project, unfortunately I use it accross several projects.
So after some time and a chat with my work mate again we come into a solution:

1. I create a function in the config class that I use for the projects

public static void LoadCustomConfigFile()
{
// open the configuration on this specific path
Configuration configuration = WebConfigurationManager.OpenWebConfiguration("/ISV/");

// get all configuration that starts with "Crm" keyword - use "Crm" keyword for Crm related settings
var crmConfigurationKeys = configuration.AppSettings.Settings.AllKeys.Where(k => k.StartsWith("Crm")).ToList();

foreach (var crmKey in crmConfigurationKeys)
{
ConfigurationManager.AppSettings.Set(crmKey, configuration.AppSettings.Settings[crmKey].Value);
}
}

2. On page load event in the ISV application

protected void Page_Load(object sender, EventArgs e)
{
// Load custom config
Config.LoadCustomConfigFile();

// do the rest of page load event
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

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