4

What is the equivalent of the .NET web.config for JavaScript code?

I'm getting to grips with the use of the configuration details in the web.config file, but I don't know what (or even if) the configuration options are for JavaScript in the page.

The user case I have is how to have a value the JavaScript, in this case a target URL, which can be changed depending upon environment, DEV / TEST / LIVE, without changing the JavaScript code

SteveC
  • 15,808
  • 23
  • 102
  • 173

1 Answers1

5

You could describe a Global JS variable in your master page and use that.

[Edit]
In your web.config have

<appSettings>
    <add key="appEnvironment" value="DEV"/>
</appSettings>

In your master page you would have something like this (I would recommend this done in the controller but for easiness)

<script type="text/javascript">
    var envType = "@ConfigurationManager.AppSettings=["appEnvironment"]";
</script>

Then all you would need to do is just change the web.config. I am presuming you are using MVC

SteveC
  • 15,808
  • 23
  • 102
  • 173
Qpirate
  • 2,078
  • 1
  • 29
  • 41
  • Thanks for the response, but won't that still necessitate editing the "code" rather than the configuration ? – SteveC May 29 '12 at 07:56