Asp.Net - Multiple projects and web.configs

Soldato
Joined
5 Mar 2003
Posts
10,771
Location
Nottingham
Hi,
I've got a web application and then a separate project where I put all the functionality that might be reused on other web apps. One of the methods is to send an email.

I've got the exchange / username and password stored in the app.config of the project where the email code is. The problem is the email never gets sent unless I copy and paste that section of the app.config into the websites web.config. Now this isn't exactly what I want as if the exchange changes, I need to change it in loads of places (one per site).

Now I could work around the problem either by hardcoding it in the method or by hardcoding access to the app.config file, but I can't help but feel I'm missing the 'obvious' and correct way to do this.

Any ideas?
Cheers.
 
What about using the IIS SMTP service which can be configured to forward emails to Exchange.

If you are asking more generally how to handle common tasks, you could use something like WCF to create a business layer that handles functionality that is common/related between all your web applications.
 
Thanks, but not the answer I was looking for :) Not really asking for an answer to the email / logic questions, more asking how you get the business logic projects to get their information from the business logic config files... not the running (website) project, without hardcoding stuff!
 
Thanks, but not the answer I was looking for :) Not really asking for an answer to the email / logic questions, more asking how you get the business logic projects to get their information from the business logic config files... not the running (website) project, without hardcoding stuff!

I don't believe that app.config files are compiled as part of the .dll, so you must include the relevant config sections in the web.config (I have exactly the same problem splitting out WCF Windows services - I have to make sure the relevant bits are copied over to the app.config for the NT Service from the WCF service library).

However, you could use a variation on Vai's suggestion. Create a WCF service that exposes a strongly typed collection of your config settings. You just then need to point all your projects at the service for their settings. A more elegant solution would be to pool your methods into this service instead, but if you aren't sharing common functions this might just be overcomplicating things.

You might also be able to add the settings to the machine.config (in the .NET folder in [C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG]) and read them from their? Never done it before so YMMV, but I think it forms the master config file for ASP.NET IIS.
 
custom configuration section may work (if I have understood the problem correctly: http://msdn.microsoft.com/en-us/library/system.configuration.configurationsection.aspx

something like:

[ConfigurationProperty("defaultConnectionStringName", DefaultValue = "LocalSqlServer")]
public string DefaultConnectionStringName
{
get { return (string)base["defaultConnectionStringName"]; }
set { base["defaultConnectionStringName"] = value; }
}

where default connection string could be SMTP username etc

Compile and use?
 
Back
Top Bottom