ASP.NET - How to read the configuration from the web.config in this case

Asked By mostafa hamdy on 26-May-11 12:20 PM
hello all
I have some web application having some configuration in the web.config like the following:
    <add  name="English"  defaultValue="En" />
    <add  name="Frensh" defaultValue="Fr" />
and I want to read properties from the  CS file , how can I read the properties using the  ConfigurationManager
please if any body get what I mean and can help me please send me or tell me about some url may help me in doing that

Ravi S replied to mostafa hamdy on 26-May-11 12:32 PM

follow this

Example 1:
<!-- This is an example Web.config file -->
            <add key="var1" value="SomeValue"/>
In this article, we will see how to read the configuration settings in the web.config using ‘javascript’.
Step 1: Create a new ASP.NET website. Add a button control to the Default.aspx.
Step 2: Right click the project > Add New Item > Web Configuration File
Add the following sample entry to the appSettings section in the web.config between the <configuration> tag as shown in the example 1:
<add key="var1" value="SomeValue"/>
Step 3: To read these entries using javascript, add the following script in the <head> tag of your Default.aspx page as shown below:
<head runat="server">
    <script type="text/javascript">
    function ReadConfigurationSettings()
        var k = '<%=ConfigurationManager.AppSettings["var1"].ToString() %>'
Step 4: Call this function on a button click and display the values of the configuration settings:
<input type="button" value="Get" onclick="ReadConfigurationSettings();" />

Ravi S replied to mostafa hamdy on 26-May-11 12:33 PM

refer the link ...

here are examples
Mihir Soni replied to mostafa hamdy on 26-May-11 01:14 PM

Here is simply how to read/write web.config file

Just scroll down there and get how to read particular attribute from the web.config file

hope this helps you

Thank you
Santosh Singh replied to Mihir Soni on 26-May-11 02:18 PM
Refer the link :

To understand web.config more better refer :