Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read web.config values from Javascript

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>

I include the following inside my java script function.

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

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

What am i missing?

like image 881
user544079 Avatar asked Jul 17 '13 22:07

user544079


1 Answers

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.

like image 50
Dusty Avatar answered Oct 20 '22 04:10

Dusty