application settings

  • Thread starter Thread starter Andy B
  • Start date Start date
A

Andy B

How hard is it to access/modify application settings in the web.config from
web pages?
 
re:
!> How hard is it to access/modify application settings in the web.config from web pages?

Quite easy...with the caveat that you'll lose all application data as a result,
because the application will restart as soon as you modify web.config.

Look into the WebConfigurationManager.OpenWebConfiguration Method :

http://msdn.microsoft.com/en-us/lib...onfigurationmanager.openwebconfiguration.aspx

http://msdn.microsoft.com/en-us/library/ms228063.aspx




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
"Which means that, apart from very exceptional circumstances, modifying
web.config at runtime is almost always the wrong solution - what are you
trying to achieve here...?"

I need to have a set of application settings that can be changed and used in
the website. Kind of like system settings profile instead of a user profile.
For an example, a setting I want to have is "Number of News articles to show
on home page?" I just don't know where the best place to keep these would
be. a DB doesn't seem to be too practicle for something like this. Possibly
some sort of settings file of some kind?
 
Sorry, I just jump in.

I use external XML file which is desterilized into my 'Config' object with
XmlSerializer when application loading (event in Global.asax). And in code I
am using that Config object

(in Psedoucode)
class clsGlobal
{
static public clsConfig _objConfig;
public static void Init()
{
_objConfig = XmlSerializer.Deserialize('~/my.xml');
}
}

Use in code.
int iLinesPerPage = clsGlobal._objConfig._iLinesPerPage;

-----------------------------------------------
To avoid watching my.xml for changes I create some dummy.aspx page (only me
or admin knows about). Which does only

clsGlobal.Init();
Response.Write("OK");

Then whenever i change my.xml i hit dummy.aspx to refresh new settings.
So basically the same thing as if in web.config except i avoid restarting
application.

But of course as Mark said you need to determine where to store your config
values based on the use. If user needs to be able to change that kind of
settings then my way might be not good idea.


George.
 
"Do you need to change this value on a regular basis?"

I don't think this particular value will need to be changed on a regular
basis. Because of the nature of the settings, I would expect that they will
be used with some regularity (at least I need to program for the
possibility).

"Do you need to change this value while the site is in use?"

All of the settings I am thinking about need to be set while the application
is in use and running.
 
Back
Top