How to get transformed value of key from Web.config

Luke

I have the following key in my Web.config file:

<appSettings>
    <add key="ImageBucketName" value="dev" />
</appSettings>

I have the following transformation in my Web.Release.Config file:

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

However, when I run my application from Visual Studio 2013 and attempt to retrieve the value of the key from with my controller, I am always getting the non-transformed version of the key.

// Get the AWS bucket name from the config file
var imageBucketName = ConfigurationManager.AppSettings["ImageBucketName"];

The same result with the following:

// Get the AWS bucket name from the config file
var imageBucketName = WebConfigurationManager.AppSettings["ImageBucketName"];

How can I ensure that I'm getting the correct Release version of the key when I'm running the application as 'Release'?

Chamila Chulatunga

Transforms won't be applied when running directly in Visual Studio - you would need to at least deploy somewhere (even if locally) first.

The rationale is something along the lines of transforms being applicable to different environments. The base web.config file represents the local (dev) environment, while the .release transforms would be applicable for prod (or prod-like) environments.

If you just want to see the transforms in action, an easy way to run them is via the command-line XDT tool available from https://ctt.codeplex.com/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to create a JSON string with key/value pairs from web.config appsettings?

From Dev

How to retrieve the value for the Key in the Web.Config using DictionarySectionHandler

From Dev

How to retrieve the value for the Key in the Web.Config via C#

From Dev

How to get default value from web.config in webapi attribute routing parameter

From Dev

Web.config is not transformed when debugging code

From Dev

How to get the property value in Laravel Blade that was transformed by Eloquent API Resource?

From Dev

How to get value from json with duplicate key?

From Dev

How to get key/value pair from NSDictionary?

From Dev

How to get particular key and value from Map

From Java

How to get dictionary value from key in a list?

From Dev

How to get a value from gson object by key

From Dev

How to get the key value from nested object

From Dev

How to get value by key from JObject?

From Dev

How to get the key from the value in firebase

From Dev

How to get particular key and value from Map

From Dev

How to get the key and the value from a dictionary?

From Dev

How to get key and value from an NSDictionary?

From Dev

how to get key of selected value from nsdictionary

From Dev

How to Get key value from parseJson()

From Dev

How to get the value for key @int from NSDictionary?

From Dev

How to get value from certain key in Java?

From Dev

JS - How to get value from object by key

From Dev

How to get value by key from ArrayList?

From Dev

How to pass value from web.config to external js file?

From Dev

How do I get a const string from Web.config?

From Dev

How to get the value from a "key = value" string from a file?

From Dev

how to get only key from key value pair in firebase ?

From Dev

How to get specific value from Web Service

From Dev

how to get a maximum of a transformed array

Related Related

  1. 1

    How to create a JSON string with key/value pairs from web.config appsettings?

  2. 2

    How to retrieve the value for the Key in the Web.Config using DictionarySectionHandler

  3. 3

    How to retrieve the value for the Key in the Web.Config via C#

  4. 4

    How to get default value from web.config in webapi attribute routing parameter

  5. 5

    Web.config is not transformed when debugging code

  6. 6

    How to get the property value in Laravel Blade that was transformed by Eloquent API Resource?

  7. 7

    How to get value from json with duplicate key?

  8. 8

    How to get key/value pair from NSDictionary?

  9. 9

    How to get particular key and value from Map

  10. 10

    How to get dictionary value from key in a list?

  11. 11

    How to get a value from gson object by key

  12. 12

    How to get the key value from nested object

  13. 13

    How to get value by key from JObject?

  14. 14

    How to get the key from the value in firebase

  15. 15

    How to get particular key and value from Map

  16. 16

    How to get the key and the value from a dictionary?

  17. 17

    How to get key and value from an NSDictionary?

  18. 18

    how to get key of selected value from nsdictionary

  19. 19

    How to Get key value from parseJson()

  20. 20

    How to get the value for key @int from NSDictionary?

  21. 21

    How to get value from certain key in Java?

  22. 22

    JS - How to get value from object by key

  23. 23

    How to get value by key from ArrayList?

  24. 24

    How to pass value from web.config to external js file?

  25. 25

    How do I get a const string from Web.config?

  26. 26

    How to get the value from a "key = value" string from a file?

  27. 27

    how to get only key from key value pair in firebase ?

  28. 28

    How to get specific value from Web Service

  29. 29

    how to get a maximum of a transformed array

HotTag

Archive