Creating a custom .config file in asp.net

与世无争的帅哥 提交于 2019-12-30 00:36:11

问题


Is there a way I can create a blah.config file in asp.net, and access the name/value pairs of nodes the same way you access items in in a regular web.config file?

(the idea is to not have to write any custom code for this).


回答1:


Chris shows one way to "externalize" part of your configuration. That works fine for certain scenarios. If you need more, you'll need to dig in a bit deeper.

For that, you should definitely check out Jon Rista's three-part series on .NET 2.0 configuration up on CodeProject.

  • Unraveling the mysteries of .NET 2.0 configuration
  • Decoding the mysteries of .NET 2.0 configuration
  • Cracking the mysteries of .NET 2.0 configuration

Highly recommended, well written and extremely helpful! He shows how to create and use custom configuration sections, and goes on to explain how to use your own blah.config instead of or in addition to standard .NET config files.

Marc




回答2:


Use the "file" attribute of the appSettings block, like so:

<appSettings file="user.config">
    <add key="Test1" value="Generic1" />
    <add key="Test2" value="Generic2" />
</appSettings>

Further explanation available here.



来源:https://stackoverflow.com/questions/837133/creating-a-custom-config-file-in-asp-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!