Using web.config as store for referenced class library's Properties.Settings class?

可紊 提交于 2019-12-08 02:09:44

问题


Folks,

This is probably very simple, but I couldn't turn up anything explicitly on point.

I have a web app (ASP.Net 4.0) that references a class library. The class library has various settings. I'd like to use the strongly-typed Properties.Settings capability within the class library. However, since class library config files are ignored under ASP.Net, I'd like the backing store for the settings to be a section of web.config as opposed to a class library-specific app.config.

I figure this is either outrightly forbidden or is as easy as pie to do. Can anyone tell me how to make it work?

Thanks,

Ann L.


回答1:


I'm not 100% sure what you're asking, but I see two possible questions:

  1. The class library has properties that are controlled (set) by the config file, but class libraries don't consume config files. If that's the case, then all you need to do is move those settings to the calling app's config file - the class library will automatically use the calling app's Web.config (or App.config, as appropriate).

  2. You want to create a custom Configuration Section, which can also be done: How to: Create Custom Configuration Sections Using ConfigurationSection

Unless I've totally misread your question (always a possibility with me :) ), I'd go with #1 as it's easier, unless there's something unique or required in your design to move you to option 2.



来源:https://stackoverflow.com/questions/6987208/using-web-config-as-store-for-referenced-class-librarys-properties-settings-cla

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