Retrieve values from the appSettings section either programmatically or declaratively. : appSettings « Configuration « ASP.NET Tutorial






<%@ 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>








16.3.appSettings
16.3.1.Storing Custom Settings in the web.config File
16.3.2.Retrieve values from the appSettings section either programmatically or declaratively.
16.3.3.Loading string from Web.config (C#)
16.3.4.Retrieve AppSetting
16.3.5.ConfigurationSettings.AppSettings