In this article I will explain with an example, how to read (get) key values of AppSettings section in ASPX page from ASP.Net Web.Config file using C# and VB.Net.
In ASP.Net Web Applications, one has to reference the System.Configuration Assembly in order to read AppSetting values from the Web.Config file.
In ASPX Page, the AppSetting values will be read from Web.Config file using Server-Side code blocks (<% %>).
 
 
Adding System.Configuration reference
The very first thing you need to do is to add reference of the System.Configuration Assembly to the project in the following way.
1. Right click on the project and click Add Reference option from the Context Menu.
Read (Get) AppSettings Key Value in ASPX page from Web.Config file in ASP.Net
 
2. From the Add Reference dialog box, click on .Net Tab and look for System.Configuration assembly. Once you find it simply select and click OK.
Read (Get) AppSettings Key Value in ASPX page from Web.Config file in ASP.Net
 
3. Once the reference is added, it will be shown in the References folder of the Solution Explorer.
Read (Get) AppSettings Key Value in ASPX page from Web.Config file in ASP.Net
 
 
Reading AppSettings value in ASPX page from Web.Config file using C# and VB.Net
Once the reference is added, you can read the AppSettings value in ASPX page from the Web.Config file in the following way.
C#
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <span><%=System.Configuration.ConfigurationManager.AppSettings["Name"]%></span>
    </form>
</body>
</html>
 
VB.Net
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <span><%=System.Configuration.ConfigurationManager.AppSettings("Name")%></span>
    </form>
</body>
</html>
 
Note: Server-Side code blocks (<% %>) cannot be used with ASP.Net controls like TextBox, Label, etc. Only exception is that if the TextBox or Label control is inside a DataBound control like GridView, Repeater, etc.