开发者

ASP.NET How to use WebConfigurationManager to get section from Specific config file?

开发者 https://www.devze.com 2022-12-30 10:52 出处:网络
I am trying to get sections from specific .config file such like \"my.config\". WebConfigurationManager.OpenWebConfiguration can get the web.config in specific path.

I am trying to get sections from specific .config file such like "my.config". WebConfigurationManager.OpenWebConfiguration can get the web.config in specific path. Maybe WebConfigurationManager.OpenMap开发者_Python百科pedWebConfiguration can reach my purpose.

Can anyone share experience?


I don't know about using the OpenMappedWebconfig thing, but this is a way to do it using a easy utility class:

http://aspalliance.com/705

If you want to have neater access to the config, then create a custom class that inherits from ConfigurationSection, then you can access the variables using syntax like MyConfig.configkey, Here's an article that describes how to create the custom class and is good for some further info:
https://web.archive.org/web/20211020133931/https://www.4guysfromrolla.com/articles/032807-1.aspx

This article shows how to do internal custom config sections:
http://www.beansoftware.com/asp.net-tutorials/multiple-config.aspx

HTH, Lance

EDIT: The aspalliance.com is down, so to tide you over, here are some other helpful links:

Here's a super-simple way to do it - http://www.codeproject.com/KB/files/custom_config_file_reader.aspx

Here's the verbose Microsoft way - http://msdn.microsoft.com/en-us/library/2tw134k3.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消