Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
In the script block in both html and aspx file, I use this piece of code below to retrieve the values in the config file:
HTML
var devServer = "<%=ConfigurationManager.AppSettings['devServer'].ToString() %>";

In the aspx, the value in the config file is retrieved well. However, in the html, this piece of code does not work. How can this problem be solved? Thanks.

What I have tried:

JavaScript - .html vs. .Net's .aspx for values in .config
Posted
Updated 11-Oct-16 7:17am

1 solution

Will go ahead to share my view on this but you can go further to look this in google and check the correctness and can get in depth knowledge.

To understand this you have to understand how a aspx page works i.e, how it is processed at the server end so that finally some client side script and html markup can be served to the requested client.

An HTML page is directly served via the webserver to the requested client so, no server side processing happens to serve plain html pages. While an aspx page has to go through certain processes. Why? Because your web browser doesn't understand asp.net rather it expects html, css and javascript. So when client requests for an aspx page, the IIS at server receives the request and sends to the ASP.Net engine which further process the content of the pages by resolving all the dependencies so that finally some html markup and script can be served to the client.

Now coming to your code block, ConfigurationManager class and it's properties can be accessed with server pages. A plain HTML page will not undergo process with ASP.Net engine and the shown variable will not be replaced by the value from configuration.

Someone, please correct me if I am wrong here.

Thanks :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900