ASP.NET Tutorial/Configuration/AppSettingsSection — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 11:57, 26 мая 2010

Get all settings for AppSettings Section

<%@ page language="C#" %>
<script runat="server">
    
    void Page_Load(object sender, System.EventArgs e)
    {
        foreach (string key in ConfigurationSettings.AppSettings) {
            this.Response.Write(string.Format("<b>{0}</b> = {1}", key, ConfigurationSettings.AppSettings[key]));
        }
    }
    
</script>
<html>
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
    
<body>
    <form id="Form1" runat="server">
    </form>
</body>
</html>


Get Configuration for application path

<%@ page language="C#" %>
<%@ import namespace="System.Web.Management" %>
<script runat="server">
    
    void Page_Load(object sender, System.EventArgs e)
    {
        string appPath = this.Request.ApplicationPath;    
        Configuration config = Configuration.GetConfigurationForUrl(appPath);
        AppSettingsSection appSettings = config.AppSettings;
        foreach (string key in appSettings.Settings) {
            this.Response.Write(string.Format("<b>{0}</b> = {1}", key, appSettings.Settings[key]));
        }
    }
    
</script>
<html>
<head runat="server">
    <title>Untitled Page</title>
</head>
    
<body>
    <form runat="server">
    </form>
</body>
</html>