InheritInChildApplications cannot be set to false - Error hosting child application under DNN

Download modified assembly for .Net 4.0

In one of earlier posts, I had described how you could host a child application under DNN. This technique had been working and still works perfectly. This week, I decided to upgrade of the existing portals from DNN 6.0 to DNN 6.01+ version. I was expecting a smooth upgrade because we did not have significant changes since first deployment of portal on DNN6.0. As soon as we opened the site, we ran into following error.

InheritInChildApplications cannot be set to "false" if the location path is referring to machine.config or the root web.config

This was just total surprise. After doing some search, I found some suggestions about splitting system.web and system.webServer sections in web.config file into two parts and keep machine key and validation etc. tags in one section and not wrap around location. The suggestions did not make much sense to me because we have been running DNN site with our current arrangement on Windows 2008 R2 for quite some time. Anyways, I tried the suggestion and the problem did not go away.

Then I started my traditional debugging process. I looked at entries in event log. And there was something interesting as shown below in one of the entries.

Exception information: 
    Exception type: ConfigurationErrorsException 
    Exception message: InheritInChildApplications cannot be set to "false" if the location 
        path is referring to machine.config or the root web.config.
   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
   at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
   at System.Configuration.Configuration..ctor(String locationSubPath, 
        Type typeConfigHost, Object[] hostInitConfigurationParams)
   at System.Configuration.ClientConfigurationHost.OpenExeConfiguration
        (ConfigurationFileMap fileMap, Boolean isMachine, 
        ConfigurationUserLevel userLevel, String exePath)
   at FiftyOne.Foundation.Mobile.Configuration.Support.GetConfigurationSectionFromAltConfig
        (String sectionName, Boolean isMandatory)
   at FiftyOne.Foundation.Mobile.Configuration.Support.GetWebApplicationSection
        (String sectionName, Boolean isManadatory)
   at FiftyOne.Foundation.Mobile.Configuration.Manager..cctor()

Towards the bottom of the stack trace, I noticed something related to 51Degrees.mob. class name. This was some code trying to load configuration files. After doing some research I found out that DNN is shipping with an open source 51mobile component to facilitate mobile device detection. This component has code that throws exception when there is a location tag in web.config file. On their site the author has provided a solution to overcome this limitation. Following code shows the fix I made to the code. This fix is based on the suggestion by 51degress authors.

private static ConfigurationSection GetConfigurationSectionFromAltConfig(string sectionName, bool isMandatory)
{
    System.Configuration.Configuration fiftyOneConfig = null;
    foreach (var file in Constants.ConfigFileNames)
    {
      string configFileName = GetFilePath(file);
      if (File.Exists(configFileName))
      {
         // Define cofniguration file(s) mapping for loading the alternate configuration.
         ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
         configFileMap.ExeConfigFilename = configFileName;
         configFileMap.MachineConfigFilename = GetFilePath("~/Web.config");
         try
         {
           fiftyOneConfig = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
         }
         catch
         {
            fiftyOneConfig = WebConfigurationManager.OpenWebConfiguration("~/51Degrees.mobi.config");
         }
         if (fiftyOneConfig != null && fiftyOneConfig.HasFile == true)
         {
            EventLog.Debug(string.Format("Getting '{0}' configuration from file '{1}'.", sectionName, configFileName));
            ConfigurationSection section = fiftyOneConfig.GetSection(sectionName);
            if (section != null)
              return section;
         }
      }
    }

    if (isMandatory)
      throw new MobileException(string.Format(
        "Could not retrieve '{0}' section from configuration files '{1}'.",
        sectionName,
        String.Join(", ", Constants.ConfigFileNames)));

    return null;
}
    

After deploying new assembly with this fix, everything worked like a charm. Although 51mobile claims to have fixed this issue but till the latest download of DNN, the problem exists. Till a fix is shipped by DNN, above code will help you move forward.

Download Binaries

I have attached compiled binaries for this assembly with the fix with this post. This binary is for .Net Framework V4.0.

comments powered by Disqus

Search

Social

Weather

9.1 °C / 48.5 °F

weather conditions Clouds

Monthly Posts

Blog Tags