Reading web.config file using JavaScript

Suppose we have the followings on our web.config file:
  1. <appSettings>  
  2. <add key="serverip" value="###.##.#.##"/>  
  3. </appSettings>  
  4.   <connectionStrings>  
  5.     <add name="conn" connectionString="Server=###.##.#.##;User=root;Password=12345;Database=test;"/>  
  6.   </connectionStrings> 
Then using the following set of steps we can read our config file.
 
Step 1:- Add the following piece of code in the head section of .aspx page.
  1. <script type="text/javascript">  
  2. function ReadConfigFile()  
  3. {  
  4.     var conStr = '<%=ConfigurationManager.ConnectionStrings["conn"].ConnectionString %>'  
  5.     alert(conStr);  
  6.     var appStr = '<%=ConfigurationManager.AppSettings["serverip"].ToString() %>'  
  7.     alert(appStr);  
  8. }  
  9. </script> 
Step-2: Now take a button and call the above function on its OnClientClick event.
  1. <asp:Button ID="Button1" runat="server" Text="display webconfig" OnClientClick="ReadConfigFile()" />