I am trying to read key value from web.config using javascript in my .aspx page. This page is included in a master page, the script block is added in the ContentPlaceHolder tag in my aspx page as below; This question was asked before here how to read values from web.config in javascript in aspx page but there was no clear solution. Someone suggested returning to server side but I am trying to avoid returning to server in order to accelerate user's work on the page ... So below is my code:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script type="text/javascript">
function CheckCountry() {
var country = '<%= System.Configuration.ConfigurationManager.AppSettings["LoginCountry"].ToString() %>';
alert(country);
}
window.onload = CheckCountry;
</script>
....
</asp:Content>
But whenever I try to run my project I get this error in the List Error box in visual Studio 2010.
I have tried also this '<%=ConfigurationManager.AppSettings["LoginCountry"].ToString() %>' but didn't work, same error was thrown ...
What could be the problem? How can I solve this and get the value of country from web.config in my aspx page?
web.config<appSettings>node look like?'from the javascript. Sometimes the editor doesn't understand javascript combined with inline code.<location allowOverride="true" inheritInChildApplications="true">tag ? Like here:<location allowOverride="true" inheritInChildApplications="true"><appSettings> <add key="LoginCountry" value="LL"/> </appSettings></location>