`
aijuans8
  • 浏览: 191554 次
社区版块
存档分类
最新评论

.Net配置文件常用配置说明

 
阅读更多

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

配置文件内容如下:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

<section name="mySection" type="System.Configuration.NameValueSectionHandler"/>

<section name="mySingleTagSection" type="System.Configuration.SingleTagSectionHandler"/>

<section name="myDictionarySection" type="System.Configuration.DictionarySectionHandler"/>

<sectionGroup name="mySections">

<section name="mySection1" type="System.Configuration.NameValueSectionHandler"/>

<section name="mySection2" type="System.Configuration.NameValueSectionHandler"/>

</sectionGroup>

</configSections>

<mySection>

<add key="key1" value="value1" />

<add key="key2" value="value2" />

</mySection>

<mySingleTagSection setting1="value1" setting2="value2" setting3="value3" />

<myDictionarySection>

<add key="DictionarySectionKey1" value="DictionarySectionValue1"/>

<add key="DictionarySectionKey2" value="DictionarySectionValue2"/>

<add key="DictionarySectionKey3" value="DictionarySectionValue3"/>

</myDictionarySection>

<mySections>

<mySection1>

<add key="mySection1_key1" value="mySection1_value1" />

<add key="mySection1_key2" value="mySection1_value2" />

</mySection1>

<mySection2>

<add key="mySection2_key1" value="mySection2_value1" />

<add key="mySection2_key2" value="mySection2_value2" />

</mySection2>

</mySections>

<appSettings>

<add key="appkey1" value="appvalue1" />

<add key="appkey2" value="appvalue2" />

</appSettings>

</configuration>

代码片断如下:

private static void TestAppSettings()

{

Console.WriteLine("TestAppSettings ...");

NameValueCollection config = ConfigurationSettings.AppSettings;

Console.WriteLine("value1:" + config["key1"]);

Console.WriteLine("value2:" + config["key2"]);

Console.WriteLine();

}

private static void TestSection()

{

Console.WriteLine("TestSection ...");

NameValueCollection config ;

config = (NameValueCollection)ConfigurationSettings.GetConfig("mySection");

Console.WriteLine("value1:" + config["key1"]);

Console.WriteLine("value2:" + config["key2"]);

Console.WriteLine();

}

private static void TestSingleTagSection()

{

Console.WriteLine("TestSingleTagSection ...");

IDictionary dic ;

dic = (IDictionary)ConfigurationSettings.GetConfig("mySingleTagSection");

Console.WriteLine("value1:" + dic["setting1"]);

Console.WriteLine("value2:" + dic["setting2"]);

Console.WriteLine("value3:" + dic["setting3"]);

Console.WriteLine();

}

private static void TestDictionarySection()

{

Console.WriteLine("TestDictionarySection ...");

IDictionary dic ;

dic = (IDictionary)ConfigurationSettings.GetConfig("myDictionarySection");

Console.WriteLine("DictionarySectionValue1:" + dic["DictionarySectionKey1"]);

Console.WriteLine("DictionarySectionValue2:" + dic["DictionarySectionKey2"]);

Console.WriteLine("DictionarySectionValue3:" + dic["DictionarySectionKey3"]);

Console.WriteLine();

}

private static void TestSectionGroup()

{

Console.WriteLine("TestSectionGroup ...");

NameValueCollection config1 ;

NameValueCollection config2 ;

config1 = (NameValueCollection)ConfigurationSettings.GetConfig("mySections/mySection1");

config2 = (NameValueCollection)ConfigurationSettings.GetConfig("mySections/mySection2");

Console.WriteLine("mySections/mySections1/value1:" + config1["mySection1_key1"]);

Console.WriteLine("mySections/mySections1/value2:" + config1["mySection1_key2"]);

Console.WriteLine("mySections/mySections2/value1:" + config2["mySection2_key1"]);

Console.WriteLine("mySections/mySections2/value2:" + config2["mySection2_key2"]);

Console.WriteLine();

}

分享到:
评论

相关推荐

    VB.NET]读写INI文件

    INI 文件是一种常用的配置文件格式,广泛应用于 Windows 操作系统中。VB.NET 提供了读写 INI 文件的功能,使得开发者可以轻松地实现应用程序的配置管理。本文将详细介绍如何使用 VB.NET 读写 INI 文件。 知识点 1: ...

    跟我一起学Visual.Studio.2005(8):ASP.NET配置管理

    《跟我一起学Visual Studio 2005(8): ASP.NET配置管理》是关于使用Visual Studio 2005进行ASP.NET应用程序配置管理的一篇教程。在这个教程中,我们将深入探讨如何有效地管理和配置ASP.NET项目,以确保其稳定运行和...

    asp.net我们常用的类的配置文件

    在ASP.NET中,配置文件是应用的核心组成部分,它允许开发者定义和管理应用程序的行为,而无需修改源代码。本文将深入探讨ASP.NET中的类配置文件及其重要性,以及如何使用它们来优化开发流程。 首先,ASP.NET框架...

    Log4.Net详细配置+dll

    1. **配置文件**:Log4Net的配置通常在应用程序的配置文件(如app.config或web.config)中进行,也可以通过代码动态配置。配置主要涉及以下几个部分:Appender(输出目标)、Layout(输出格式)、Filter(过滤规则)...

    .net常用开发类 .net常用类 全都 是精华,累计

    ### .NET配置文件处理 在.NET框架中,应用程序通常会依赖于配置文件来进行各种设置与参数的存储。这些配置文件允许开发者和系统管理员调整应用的行为,而无需更改代码本身。其中最常用的配置文件类型是`Web.config`...

    ASP.Net学习之常用模块整理

    ### ASP.Net学习之常用模块整理 #### 一、前言 在进行ASP.NET项目的开发过程中,我们会遇到各种各样的功能需求和技术挑战。每一次项目实践都是一次宝贵的学习经历,不仅能够提升我们的技术能力,还能帮助我们积累...

    asp.net文件上传

    通过以上内容,我们可以看到ASP.NET中的文件上传功能涉及到多个方面的知识和技术,包括前端页面设计、服务器端逻辑处理、配置文件设置等。掌握这些知识点可以帮助开发者更好地实现文件上传功能,并确保其稳定性和...

    asp.net常用语句

    ASP.NET应用程序的部署涉及编译、配置文件调整以及文件的上传。Visual Studio提供了一键发布功能,简化了部署过程。 以上就是ASP.NET中的一些常用语句和概念,它们构成了ASP.NET开发的基础。熟练掌握这些知识点,将...

    .NET下常用类库介绍

    3. **System.Configuration**: 用于管理.NET应用程序的配置设置,使得开发者能够轻松地读取和修改配置文件中的参数。 4. **System.ComponentModel**: 包含了.NET组件模型,提供组件的设计时特性和事件驱动编程的...

    c#自定义XML配置文件解析 .Net Framework

    总结,自定义XML配置文件解析在.NET Framework中是一项常用且强大的功能。通过重写`ConfigurationSection`,我们可以轻松地创建符合项目需求的配置结构,再结合自定义的配置工具类,使得配置信息的管理和使用变得...

    关于ASP.NET的权限控制

    在ASP.NET中,权限控制主要依赖于配置文件(如Web.config)来实现,通过对不同角色和用户的访问权限进行设定,可以实现对页面和其他资源的访问控制。 一、权限控制基础 在ASP.NET中,权限控制主要基于三种机制:...

    .NET访问配置文件app.config的功能详解

    其中,`app.config`文件是一种常用的配置文件,它采用XML格式来存储配置数据。.NET框架内置了一系列功能,使开发者能够方便地读取、修改这些配置信息。 #### app.config文件概述 `app.config`文件是一个XML格式的...

    asp.net FCKeditor 配置例子

    2. **Web.config**: ASP.NET项目的配置文件,用于设置应用程序的配置信息,如连接字符串、安全设置、路由规则等。在这个例子中,可能需要添加对FCKeditor相关路径的配置,或者设置允许上传的文件类型和大小。 3. **...

    ASP.Net常用工具类《很全面》

    Cache、CSV文件转换、DEncrypt、FTP操作类、JS、Json、Mime、PDF、Properties、ResourceManager、XML操作类、弹出消息类、导出Excel、分词辅助类、汉字转拼音、配置文件操作类、日历、上传下载、时间操作类、视频...

    ASP.NET 26个常用性能优化方法

    ### ASP.NET 26个常用性能优化方法详解 #### 一、数据库访问性能优化 **1. 连接池管理** - **背景**: 数据库连接是昂贵的操作,尤其是在频繁地打开和关闭连接的情况下。每次创建连接都需要进行身份验证,这会占用...

    ASP.NET配置文件Web.config用法详解

    ASP.NET配置文件Web.config是ASP.NET Web应用程序的核心配置文件,用于存储和管理应用程序的各种设置。它是一个基于XML的文本文件,允许开发者自定义和控制应用的行为。以下是对Web.config文件中一些关键配置节的...

    ASP.Net应用中常见的文件类型

    .web.config 文件是 ASP.NET 应用程序的核心配置文件。它包含了应用程序的配置设置,如连接字符串、路由规则等。 ### 14. CSS 样式表文件(.css) CSS (Cascading Style Sheets) 用于定义 HTML 或 XML 文档的外观...

    .NET框架设计 模式、配置、工具 王清培(著)

    - **App.config/Web.config文件**:这是.NET应用程序中最常用的配置文件,它们使用XML格式存储配置信息。对于Windows Forms应用程序,使用的是App.config;而对于Web应用程序,则是Web.config。 - **配置节**:为了...

    PTC Creoc常用配置文件

    资源描述:本文件为creo常用配置文件。详细表述见https://blog.csdn.net/qq_39979317/article/details/107569930 使用方法:下载此文件,替换安装目录D:\Creo6.0\PTC\Creo 6.0.0.0\Common Files\text目录下的config....

Global site tag (gtag.js) - Google Analytics