Multiple web applications and web.config

G

Guest

I've developed an single sign on web application that we'd like to use with
all the applications we're developing. The application's connection string
is stored in web.config. I've gotten some basic functionality worked out and
I'm attempting to test it on another application, whose connections string to
another database is also stored in web.config. I make a reference in the
testing application to the authentication application dll, but when I run the
test, the authentication app uses the web.config file of the testing
application. Is there a way I can force it to use the web.config file in
it's own application?
 
K

Klaus H. Probst

No, assemblies will read the config file that is "mapped" to the process
under which they are running. DLLs have no "app.config" or anything like
that; they use the one the framework loads for the host EXE.

In this case your library is running under the IIS process and that means
the framework will load the web.config that corresponds to the web
application.

You could of course read the XML using a relative path and normal DOM/XPath
methods, but System.Configuration would be out of the picture and you'd have
a host of different problems.

If you need centralized configuration settings you should save them to a
separate file under, say, \Documents And Settings\All Users\Application
Data\MyApp\... or use the HKLM\Software section of the registry.
 
N

Neil Stevens

Alternatively you could try section groups in the config file and write your
own custom configuration section handler.

Your config sections would look something like this:

<sites>
<sites
... Global Site Settings<siteSettings>
<clear/>
<add name="SiteName1"
property="Property1"
setting="Setting1"
... etc />
... More add statements per site
</siteSettings>
</site>
</site>

Then you would need to create a class that will load the configurations
settings and store them in say a hash table with the siteName as the key,
you can then retrieve these by a property call passing in the siteName to
get the correct settings.

You would also need an internal class that implements the
IConfigurationSectionHandler, which has one method Create, this would
instantiate your configuration class, load the values from the xml and then
return the instantiated object.

All sounds complicated but its quite straight forward, if you want some
sample code let me know.

Hope this helps
Regards
Neil
 
G

Guest

I didn't really want to combine the config files because some of the
consuming applications will reside on different servers. I had already tried
writing a function to pull the SiteSettings into a hash table, but I still
ran into the following problem.
Project A references Project B,
Project B has a function GetSiteSettings that reads an XML file, mapped

using "AppDomain.CurrentDomain.BaseDirectory" + "web.config"
Calling GetSiteSettings from Project B gets me the file I want, in
project B dir.
Calling GetSiteSettings from Project A gets me the file from the project
A dir.

What I'm trying to do is have GetSiteSettings() get the web.config file from
the project B directory regardless of which project calls it. I'm thinking I
may just have to expose these functions as a webmethods.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top