Using Web.config file outside of ASP

T

Timm

I'm trying to use ASP objects (basically formed and populated based on
Web.Config settings) and I want to use them in a different non-asp program
with minimal reprogramming. So, my question is how do I mock up what ASP
does to read the Web.Config file? I've tried messing around in the
System.Configuration library and haven't been able to find anything from
taking a quick look at the objects and their methods (for the goal of
populating the application's ConfigurationSettings object). Any suggestions
are appreciated.
 
G

Guest

It's just an XML file.
Does whatever you are trying to write in have the ability to read them? It's
just a class with properties that pull from the XML
 
T

Timm

The class I'm trying to write to is a read only class with 2 methods for
getting settings out of it. I haven't found any methods within the
System.Configuration that says explicitly "this method will load an
application's ConfigurationSettings from an XML file".
 
T

Timm

Sorry, I probably didn't word this properly. ConfigurationSettings is a
Read-Only class, so I can't write to it explicitly by putting this line of
code: ConfigurationSettings.AppSetting("SomeSetting") = "Foo Value". It will
error out if i do that.

So what I need is some explanation on how ASP populates this class, because
there has to be a method that has access to write properties to the
ConfigurationSettings.
 
G

Guest

What I'm saying is DONT use the built in. Simply write a class that has an
XML reader in it and manually parse the .config file (it's just a fancy XML
file). You can make the individual nodes into Properties in your class, and
even make them read-only if you want.

You seem to be stuck on wanting to try to use the .net ConfigurationSettings
stuff, dont. Just write your own.. MySite.MySiteSettings or whatever.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
 
T

Timm

Yes, I am stuck on wanting to use the .Net ConfigurationSettings. It's the
curse of the sutsourced software we bought for a quick solution. I could do
you said and manually parse out the XML file, but thing is I would then have
to recode serveral different classes to accomodate to this (and then for
future changes in the object we would have to maintain two sets of objects).
It may end up that I have to do this, but I just need to find out if there's
a quick way to just get the settings in just like ASP does. If there are any
good books that talk about the ASP framework and the really in depth
workings (as far as extending base classes and whatnot) of it I could
probably take those as suggestions as well.
 
G

Guest

Ahhh... you never indicated you HAD to use the existing class...

Let me start over. What is the exact functionality you need that the
ConfigurationSettings doesn't give you?
 
T

Timm

Sorry about that. The ability to explicitly load the ConfigurationSettings
from say calling a method with a path to an Web.Config file (something along
the lines of like System.Configuration.LoadConfigurationSettings(XMLPath)).
 
G

Guest

Actually... let me rephrase...
It's fixed to "./web.config" and will continue to crawl up to "~/" checking
each folder for another web.config.

The settings are a conglomerate of all the web.config files in the path from
the folder you are in to the root of the VD-Application

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com



Timm said:
Sorry about that. The ability to explicitly load the ConfigurationSettings
from say calling a method with a path to an Web.Config file (something along
the lines of like System.Configuration.LoadConfigurationSettings(XMLPath)).
 
G

Guest

Is the "different non-asp program" a .NET application like an EXE or
Windows/Web Service?

If so, how about copying the sections needed from web.config to the
app.config of the client application that consumes these assemblies?..

Also, you may consider keeping the settings for assemblies in a common
config file and all instances of the assembly could refer the same file..

samples here http://weblogs.asp.net/pwilson/archive/2003/04/09/5261.aspx
 
T

Timm

Yes, this is a program that is "different non-asp program" category. VB.Net
EXE to be specific.
 
G

Guest

According to Curt_C, it seems that Web.config is the ONLY file can be
modified via ASP.net Web Site Administrator Tool or Configuration class.

Was there any class from ASP .net available to read/modify to our own
additional configuration file (as an xml file) for settings our application
purpose?! :(

IS there any?!!!!
 
G

Guest

Any XML file you want...
What I was trying to get at is that you dont have to use the web.config for
everything. Make a config.xml and a class in the backend called MyConfigs
then you can do whatever you want with it. Put it into a BasePage that you
set all your others to inherit from and POOF, you'd never know the difference
from the web.config (cept maybe that it's not "protected" by IIS).

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
 
T

Timm

This answered my post by the way. Thanks.

Sreejith Ram said:
Is the "different non-asp program" a .NET application like an EXE or
Windows/Web Service?

If so, how about copying the sections needed from web.config to the
app.config of the client application that consumes these assemblies?..

Also, you may consider keeping the settings for assemblies in a common
config file and all instances of the assembly could refer the same file..

samples here http://weblogs.asp.net/pwilson/archive/2003/04/09/5261.aspx
 
G

Guest

Joann,

If you copy the config info from web.config file to the APP.CONFIG of the
client application that consumes the assemblies or a common config file, the
System.Configuaron class would read it just like web.config ..

More about App.config file
http://msdn.microsoft.com/library/d...e/html/cpconapplicationconfigurationfiles.asp

More about reading common config file
http://weblogs.asp.net/pwilson/archive/2003/04/09/5261.aspx

If you are looking to add CUSTOM TAGS to web.config , this may help
http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=90


Looks like TIM could figure it out with app.config any ways
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top