WebConfigurationManager 类
来源:互联网 发布:ipad和手机同时上淘宝 编辑:程序博客网 时间:2024/05/17 06:25
在配置文件应用于 Web 应用程序时提供对配置文件的访问。
System.Web.Configuration.WebConfigurationManager
程序集: System.Web(在 System.Web.dll 中)
WebConfigurationManager 类型公开以下成员。
使用 WebConfigurationManager 类可以访问计算机和应用程序信息。
使用 WebConfigurationManager 是处理与 Web 应用程序相关的配置文件的首选方法。 对于客户端应用程序,请使用 ConfigurationManager 类。
您的应用程序可以扩展 System.Configuration 类型或直接使用它们来处理配置信息,如下面的列表中所述。
Handling configuration . 若要使用标准类型处理配置信息,请使用下列方法之一:
Accessing a section . 若要访问应用程序的配置信息,必须使用 WebConfigurationManager 提供的 GetSection 方法之一。 对于 <appSettings> 和 <connectionStrings>,可以使用 AppSettings 和 ConnectionStrings 属性。 上面提到的方法执行只读操作,使用配置的单个缓存实例,并且可识别多线程。
Accessing configuration files . 应用程序能够读写任何级别的配置设置,不管是自己的还是其他应用程序或计算机的,也不管是本地的还是远程的。 可以使用WebConfigurationManager 提供的 open 方法之一。 这些方法将返回 Configuration 对象,该对象又提供处理基础配置文件所需的方法和属性。 这些方法执行读取或写入操作,而且每次打开文件时都会重新创建配置数据。
Advanced configuration . 以下类型提供了更高级的配置处理方法:SectionInformation、PropertyInformation、PropertyInformationCollection、ElementInformation、ContextInformation、ConfigurationSectionGroup 和ConfigurationSectionGroupCollection。
Extending configuration standard types . 通过使用编程模型或特性化模型扩展标准配置类型(如 ConfigurationElement、ConfigurationElementCollection、ConfigurationProperty和 ConfigurationSection),您还可以提供自定义的配置元素。 有关如何以编程方式扩展标准的配置类型的示例,请参考 ConfigurationSection 类。 有关如何以特性化模型扩展标准的配置类型的示例,请参考 ConfigurationElement 类。
Configuration 类允许进行编程访问以编辑配置文件。 可以使用 WebConfigurationManager 提供的 open 方法之一。 这些方法将返回 Configuration 对象,该对象又提供处理基础配置文件所需的方法和属性。 可以按如下方式访问这些文件以进行读取或写入。
使用 GetSection 或 GetSectionGroup 读取配置信息。 请注意,进行读取操作的用户或进程必须具有以下权限:
在当前配置层次结构级别下对配置文件的读取权限。
对所有父级配置文件进行读取的权限。
如果您的应用程序需要对其自身的配置进行只读访问,则建议您使用 GetSection 方法。 这些方法提供对当前应用程序的缓存配置值的访问;与 Configuration 类相比,这样做可以提供更好的性能。
如果使用采用 path 参数的静态 GetSection 方法,则该路径参数必须引用正在其中运行代码的应用程序,否则将忽略该参数并返回当前运行的应用程序的配置信息。
使用 Save 方法之一写入配置信息。 请注意,进行写入操作的用户或进程必须具有以下权限:
对配置层次结构中当前级别的配置文件和目录的写入权限。
对所有配置文件的读取权限。
下面的示例演示如何使用 访问配置信息。
GetSection 方法。
// Show how to use the GetSection(string). // to access the connectionStrings section. static void GetConnectionStringsSection() { // Get the connectionStrings section. ConnectionStringsSection connectionStringsSection = WebConfigurationManager.GetSection("connectionStrings") as ConnectionStringsSection; // Get the connectionStrings key,value pairs collection. ConnectionStringSettingsCollection connectionStrings = connectionStringsSection.ConnectionStrings; // Get the collection enumerator. IEnumerator connectionStringsEnum = connectionStrings.GetEnumerator(); // Loop through the collection and // display the connectionStrings key, value pairs. int i = 0; Console.WriteLine("[Display the connectionStrings]"); while (connectionStringsEnum.MoveNext()) { string name = connectionStrings[i].Name; Console.WriteLine("Name: {0} Value: {1}", name, connectionStrings[name]); i += 1; } Console.WriteLine(); }
.NET Framework
受以下版本支持:4.5、4、3.5、3.0、2.0- WebConfigurationManager 类
- C#使用WebConfigurationManager类修改Web.config文件
- C#使用WebConfigurationManager类修改Web.config文件
- 读取web.config配置的类WebConfigurationManager与ConfigurationManager对比
- WebConfigurationManager相关
- WebConfigurationManager读写配置文件
- WebConfigurationManager 使用技巧
- WebConfigurationManager.OpenWebConfiguration("~")未能映射路径
- asp.net 用WebConfigurationManager读取和修改配置文件
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- acm--小球自由下落问题
- android有关paint属性设置 .
- 离开你,我一样活的很好
- dll的def文件与__declspec(dllexport)导出函数方式比较
- 搜索引擎-倒排索引基础知识
- WebConfigurationManager 类
- String StringBuffer StringBuilder 基础
- VS2008远程调试方法
- 小程序
- HttpClient 4.01 使用总结
- Weka中Apriori算法实用与分析
- CodeMirror与jquery UI-Tabs混合使用 注意事项
- cocos2d-x for android:CCSprite 精灵动画(转)
- android之通过USB插拔流程来了解android UEvent