By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,117 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,117 IT Pros & Developers. It's quick & easy.

Multiple web applications and web.config

P: n/a
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?
Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
--
Klaus H. Probst, MVP
http://www.vbbox.com/
"Craig" <Cr***@discussions.microsoft.com> wrote in message
news:13**********************************@microsof t.com...
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?

Jul 21 '05 #2

P: n/a
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

"Klaus H. Probst" <us*******@simulplex.net> wrote in message
news:uR**************@TK2MSFTNGP11.phx.gbl... 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.
--
Klaus H. Probst, MVP
http://www.vbbox.com/
"Craig" <Cr***@discussions.microsoft.com> wrote in message
news:13**********************************@microsof t.com...
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?


Jul 21 '05 #3

P: n/a
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.

"Neil Stevens" wrote:
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

"Klaus H. Probst" <us*******@simulplex.net> wrote in message
news:uR**************@TK2MSFTNGP11.phx.gbl...
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.
--
Klaus H. Probst, MVP
http://www.vbbox.com/
"Craig" <Cr***@discussions.microsoft.com> wrote in message
news:13**********************************@microsof t.com...
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?



Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.