什么是相当于web.config的JavaScript代码? [英] What is the equivalent of web.config for JavaScript code?

查看:157
本文介绍了什么是相当于web.config的JavaScript代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相当于.NET web.config for JavaScript code?

web.config 文件中使用配置详细信息,但我不知道页面中的JavaScript的配置选项是什么(即使) 。



我的用户案例是如何获得一个值 JavaScript ,在这种情况下是一个目标URL,而不改变 JavaScript 代码

,因此可以根据环境改变 DEV / TEST / LIVE =h2_lin>解决方案

您可以在您的母版页中描述一个全局JS变量并使用它。



/ strong>]

在您的 web.config 中有

 < appSettings> 
< add key =appEnvironmentvalue =DEV/>
< / appSettings>

在你的母版页中,你会有这样的东西容易)

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

然后你需要做的只是改变 web.config 。我假设你正在使用MVC


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

解决方案

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

这篇关于什么是相当于web.config的JavaScript代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆