locked
Multiple Web.Config RRS feed

  • Question

  • User1002530435 posted

    I have few questions below.

    *I am having 2 web.config one in root and another in subfolder.If i change any thing in the config file at sub folder,will the same will be updated automatically in rootfolder config file once i run the application?

    *If i specify same connectionstring/keys in both config files at root & subfolder.When we execute the application,which connection string/key values will be taken for execution,will it root folder or subfolder?

    *Is there any exception will throw if i have same key name values in multiple config values?

    *Which scenario we go for multiple config file?

    Tuesday, July 15, 2014 11:55 PM

Answers

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 16, 2014 12:06 AM
  • User-1454326058 posted

    Hi ssramvinay,

    First, please refer to oned_gk’s reply.

    I am having 2 web.config one in root and another in subfolder.If i change any thing in the config file at sub folder,will the same will be updated automatically in rootfolder config file once i run the application?

    For this requirement, you could use file attribute.

    1. Create a config file in a new folder (E.g. appSettings.config)
      <?xml version="1.0"?>
      <appSettings>
        <add key="KeyTwo" value="LoadedFromExternalFileTwo" />
        <add key="KeyThree" value=" LoadedFromExternalFileThree" />
      </appSettings>
      
    2. In your root web.config file
       <appSettings file="config\appSettings.config">
          <add key="KeyOne" value="LoadedFromWebConfigone" />
          <add key="KeyTwo" value="LoadedFromWebConfigtwo" />
          <add key="KeyThree" value="LoadedFromWebConfigthree" />
        </appSettings>

    After that the root web.config file will load the extra file (Override the by the key)

    If i specify same connectionstring/keys in both config files at root & subfolder.When we execute the application,which connection string/key values will be taken for execution,will it root folder or subfolder?

    If the request page is in the subfolder, it will use the subfolder web.config file data if it has.

    If the request page is in the rootfolder, it will use the root folder’s web.config file.

    Is there any exception will throw if i have same key name values in multiple config values?

    No, just override.

    Which scenario we go for multiple config file?

    For example: different setting in subfolder’s page.

    Thanks

    Best Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 17, 2014 1:10 AM

All replies

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 16, 2014 12:06 AM
  • User-1454326058 posted

    Hi ssramvinay,

    First, please refer to oned_gk’s reply.

    I am having 2 web.config one in root and another in subfolder.If i change any thing in the config file at sub folder,will the same will be updated automatically in rootfolder config file once i run the application?

    For this requirement, you could use file attribute.

    1. Create a config file in a new folder (E.g. appSettings.config)
      <?xml version="1.0"?>
      <appSettings>
        <add key="KeyTwo" value="LoadedFromExternalFileTwo" />
        <add key="KeyThree" value=" LoadedFromExternalFileThree" />
      </appSettings>
      
    2. In your root web.config file
       <appSettings file="config\appSettings.config">
          <add key="KeyOne" value="LoadedFromWebConfigone" />
          <add key="KeyTwo" value="LoadedFromWebConfigtwo" />
          <add key="KeyThree" value="LoadedFromWebConfigthree" />
        </appSettings>

    After that the root web.config file will load the extra file (Override the by the key)

    If i specify same connectionstring/keys in both config files at root & subfolder.When we execute the application,which connection string/key values will be taken for execution,will it root folder or subfolder?

    If the request page is in the subfolder, it will use the subfolder web.config file data if it has.

    If the request page is in the rootfolder, it will use the root folder’s web.config file.

    Is there any exception will throw if i have same key name values in multiple config values?

    No, just override.

    Which scenario we go for multiple config file?

    For example: different setting in subfolder’s page.

    Thanks

    Best Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 17, 2014 1:10 AM