Find out which web.config(s) have been loaded

1.1k views Asked by At

I'm encountering an error indicating that the web.config being loaded by this particular sub-project of my solution has a connectionstring that conflicts with an existing entry from an already-loaded web.config (Exception message is: Additional information: The entry 'connStr' has already been added.)

Is there a way to easily find out the list of all web.configs loaded/being loaded, so that I can ascertain where to conflict is arising

2

There are 2 answers

1
DavidG On BEST ANSWER

There is only one web.config that will be loaded, however, it will inherit from your machine configuration. For IIS this is here:

%windir%\Microsoft.NET\Framework\framework_version\CONFIG\machine.config

And for IIS Express in one of these places:

%userprofile%\documents\iisexpress\config\applicationhost.config
%userprofile%\my documents\iisexpress\config\applicationhost.config
$(solutionDir)\.vs\config\applicationhost.config (only for Visual Studio 2015 and above)

So you can remove the duplicate from there, or add a remove entry in your web.config, for example:

<connectionStrings>
  <remove name="MyConnection" />
  <add name="MyConnection" connectionString="..." providerName="System.Data.SqlClient" />
</connectionStrings>
0
m.liboon On

I've had this problem before, I added inheritInChildApplications="false" in my main web.config. This way I know that my sub web.config will not have any conflict.