Problems with Web.Config

Asked

Viewed 775 times

2

I am having difficulty using several web.config on my system. In my web.config main i have the following configuration:

<configuration>
  <appSettings>
    <add key="BASE_URL" value="/mvc/" />
  </appSettings>
</configuration>

And in my file web.release.config i have the following modification:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add key="BASE_URL" value="/mvc" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
  </appSettings>
</configuration>

But when I call the estate BASE_URL, it is returning me the value of the main config and not in the modifier, even if I use the Release configuration to build the project.

I’m using C# MVC4 in VS2013

2 answers

1

There are three Web.config settings:

  • Web.config - Is used in any Configuration Manager (Debug/Release) situation while you are running your application directly through Visual Studio.
  • Web.Debug.config - Used for publishing when Configuration Manager is in Debug
  • Web.Release.config - Used for publishing when Configuration Manager is in Release

So you can achieve three situations where your variables can be changed, I particularly find this advantageous in situations that deal with local addresses, the configuration Web.config points to a physical location on my machine (e.g.: C:/Test/), and the others point to the respective IIS virtual addresses (e.g.: /Debug/Files/ for Debug and /Release/Files/ for Release).

0

Go to the BUILD Menu -> Configuration Manager.

In the "Active Solution Configuration" combo, change to release. Check that the file . config that will be used is actually the web.config.release.

  • Thanks for the tip Thiago, but I j[a had done this, I found that web.config differentials only work when we publish the project, but it was worth the intention

Browser other questions tagged

You are not signed in. Login or sign up in order to post.