1

I have a child MVC application running in IIS8.5 under another parent MVC application.

As expected, the child application inherits the parents Web.Config settings.

The issue that I have is that the child application inherits the <EntityFramework> section which I need to prevent it doing. How do I achieve this?

I've seen a number of different questions that ask a very similar question but none of them have worked to prevent <EntityFramework> inheritance.

I have so far tried:

  • Issolating the application pool of the child application
  • Changing the directory to a virtual directory
  • Adding <virtualDirectoryDefaults allowSubDirConfig="false" /> within the applicationHost file
  • Adding enableConfigurationOverride="false" to the application pool profile in the applicationHost file

Update
I'm specifically having issues with code first migrations. The following <context> is inherited from the parent Web.config file but is not wanted in the child application:

<context type="SomeApp.Models.DataContext, SomeApp">
    <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[SomeApp.Models.DataContext, SomeApp], [SomeApp.Migrations.Configuration, SomeApp]], EntityFramework, PublicKeyToken=someToken">
        <parameters>
            <parameter value="SomeConnection_DatabasePublish" />
        </parameters>
    </databaseInitializer>
</context>

The main issue is that this context has a dependency on a dll that is not in the child application.

Community
  • 1
  • 1
Gareth
  • 5,140
  • 5
  • 42
  • 73
  • You could possibly try to override the config programmatically, whatever EF reads from the config, just add your code that resets it all. Without more details on what actual settings cause you trouble, no specific code snippets can be included. – Wiktor Zychla Sep 01 '16 at 14:46
  • @WiktorZychla Thanks, I've updated the question to demonstrate the `` that is being inherited. – Gareth Sep 01 '16 at 14:52
  • Have you tried to override it to anything else, like an empty list of migrations or even another initializer? – Wiktor Zychla Sep 01 '16 at 14:54
  • @WiktorZychla Do you mean in the application itself rather than through IIS? Thanks – Gareth Sep 01 '16 at 14:57

1 Answers1

1

In the web.config file for the parent application, wrap the elements you don't want to be inherited in location elements with inheritInChildApplications set to false:

<location inheritInChildApplications="false">
    <context type="SomeApp.Models.DataContext, SomeApp">
        <databaseInitializer type="...">
            <parameters>
                <parameter value="SomeConnection_DatabasePublish" />
            </parameters>
        </databaseInitializer>
    </context>
</location>

location Element (ASP.NET Settings Schema)

Richard Deeming
  • 29,830
  • 10
  • 79
  • 151
  • Thanks for the suggestion, the context is automatically generated when the parent application is published so I'm unable to control it – Gareth Sep 01 '16 at 19:35