开发者

.Net Configuration files confusion

We've got a somewhat complex project that the original developers split into multiple projects for organization purposes. What this means to me is that I've got an ASP.Net site that has a web.config and contains all sorts of good settings, and another project that compiles to a DLL that has it's own .config file, app.config.

In the DLL, it would be very nice to be able to access all the AppSettings that I have i开发者_JS百科n the ASP.Net proejct's web.config file.

Is this possible? Is it good practice? I don't really want to copy and paste the same information and have to manually keep them in synch between the 2 (actually there might be up to 20 -- it's a large project and someone organized it to an absurd level) .config files.

Any suggestions or best practices?


This is actually default behavior - ConfigurationManager.AppSettings read the current web.config for all DLLs.
Sometimes .config files are created for other projects (or dlls), but they are not used in the site and should be merged into web.config.


System.Web.Configuration.WebConfigurationManager.AppSettings accesses the web.config from any class library. Just be sure to add a reference to System.Configuration and System.Web to any library needing to access this.

And to answer your question about standard pratice, yes it is common to store application key/values in the web.config to keep things centralized in ASP.NET web applications and web sites. In your web.config just use the <appSettings> section as you normally would in app.settings files.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜