从Javascript读取web.config值 [英] Read web.config values from Javascript

查看:81
本文介绍了从Javascript读取web.config值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Java脚本从web.config文件中读取应用程序密钥.要读取的web.config密钥

I want to read an app key from the web.config file via java script. The web.config key to be read

<appSettings>
      <add key="Key1" value="value1" />
<appSettings>

我在Java脚本函数中包含以下内容.

I include the following inside my java script function.

function Evaluate() {
    var key = '<%=ConfigurationManager.AppSettings["Key1"].ToString() %>';
    alert(key);
}

但是,我最终在警报中得到了<%= ConfigurationManager.AppSettings ["Key1"].ToString()%> .

However, I end up getting <%=ConfigurationManager.AppSettings["Key1"].ToString() %> in the alert.

我想念什么?

推荐答案

<%= => 标记只有在 .aspx内时才会执行.代码>文件.如果将其放在.js文件中,则它将与其他任何文本一样.为了使代码正常工作,必须将发布的javascript嵌入.aspx文件中.

The <%= => tag is only going to execute if it is within a .aspx file. If you place it within a .js file, then it will just be like any other text. In order for your code to work, the javascript you posted would have to be embedded within the .aspx file.

这篇关于从Javascript读取web.config值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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