App.config vs web.config... Help!

App.config vs web.config... Help!

Old forum URL: forums.lhotka.net/forums/t/2002.aspx


JCannelos posted on Tuesday, December 19, 2006

Guys,

Please forgive if this is "duh!". I have a consulting tracker application with both CSLA business objects (ConsultingTracker.Library) and a web client (CTWeb), similar to the book.

I have a web.config file with an <appSettings> section that defines things like how long to cache certain items, et. In the Library, I have an app.config file which defines some other settings like <connectionStrings>. When my app runs, I run a static connection string lookup like this:

return ConfigurationManager.ConnectionStrings["MyString"].ConnectionString;

This is in a static class IN by business objects library, NOT in the web client however it is still trying to get the connectionString settings from the web.config, rather than the app.config. Arrgh!

I do have it set up to run locally (no remoting or anything like that), so I can see how one setting file should take precedence over the other. If I define the connectionString in the web.config file, everything works fine. I just wanted to keep some settings local to the library (in app.config) and some local to the client (in web.config).

Is this possible?

Thanx!

J'son

JCannelos replied on Tuesday, February 13, 2007

Does anyone have any idea on this one? Still curious as to why I need to declare my connection strings in my web app...

Thanx...

J'son

JCannelos replied on Tuesday, February 13, 2007

Does anyone have any idea on this one? Still curious as to why I need to declare my connection strings, et in my web app...

J'son

ajj3085 replied on Tuesday, February 13, 2007

If you're not using remoting, then your connection string needs to be in the Web.config for your web application.  It sounds like you're trying to use an app.config for your dll; this is not how .Net works.  Your library dll will still use the Web.config file.

Bowman74 replied on Tuesday, February 13, 2007

Your DLL will use the config file for the host process, not one specific to that DLL.  So if your dll is being called from an application in IIS it will use the application's web.config file.  If it is being called from a Winforms app called MyApp.exe it will use MyApp.exe.config.  It will not use a file called app.config or even MyDllName.dll.config (OK, it will if you are using nunit but I don't want to go into what it is doing to make that so, let's just say some reflection is involved).

When you have a solution with a Winforms application it may have a file in it called App.config.  But you will notice when it is compiled that it will copy that file into the output directory (usually under bin) and rename it to MyApp.exe.config.

So if your DLL is being used by an application in IIS, web.config is the file you need to place your settings in.

Does this make sense?

Thanks,

Kevin

Copyright (c) Marimer LLC