Mega Code Archive

 
Categories / ASP.Net Tutorial / Configuration
 

Retrieve values from the appSettings section either programmatically or declaratively

<%@ Page Language="C#" %> <%@ Import Namespace="System.Web.Configuration" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server">     void Page_Load()     {         lblWelcome.Text = WebConfigurationManager.AppSettings["welcome"];     } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">     <title>Show AppSettings</title> </head> <body>     <form id="form1" runat="server">     <div>     <asp:Label         id="lblWelcome"         Runat="server" />     <hr />     <asp:Literal         id="ltlCopyright"         Text="<%$ AppSettings:copyright %>"         Runat="server" />     </div>     </form> </body> </html> File: Web.config <configuration>   <appSettings>     <add key="welcome" value="Welcome to our Web site!" />     <add key="copyright" value="Copyright (c) 2007 by the company" />   </appSettings> </configuration>