get/set data web.config

  • Thread starter Thread starter John Devlon
  • Start date Start date
J

John Devlon

Hi

Does anyone have the correct syntax to get and set the system settings in
the web.config file ?

I would like to read and change the smtp server, login, password and from
adress....

thanx

John
 
Thanx Mark,

I didn't know that.... Better to store the data somewhere else then....

John
 
John Devlon brought next idea :
Thanx Mark,

I didn't know that.... Better to store the data somewhere else then....

John

The values you mention seem pretty static, so a one-time configuration
at install is all that is needed. In that case web.config is fine.
Values that have to be changed frequently are best kept elsewhere (some
custom config file, database)

Hans Kesting
 
Very much so.

In addition, it can be impossible to update web.config from your app
(definitely in 1.x), as the app locks the file. Unless you are truly working
with configuration elements, I would store in an XML file or a database.

In .NET 2.0, you can specify additional configs, that you can alter while
the site is running, if these truly are "dynamic" config elements, but I
would consider metadata tables in a database first.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
John Devlon said:
Thanx Mark,

I didn't know that.... Better to store the data somewhere else then....

John
 
Mark,

Do you think reading and writing to a resource file using a shared class is
a good solution ?

Thanx

John

 
You can try this trick:


<?xml version = "1.0" encoding = "utf-8" ?>

<configuration>

<appSettings file="CustomAppSettings.config" >

</appSettings>

</configuration>



Contents of CustomAppSettings.config

--start, do not include this line
<appSettings>

<add key="demokey1" value="demovalue1" />

</appSettings>

--end, do not include this line


And this is Peter's great writeup about it.


http://www.eggheadcafe.com/tutorial...180-c1f564b41f85/some-aspnet-20-configur.aspx


I don't think the webapp is recycled with this method. I haven't
specifically tested it.

...

Don't forget to add POST BUILD events if you doing non asp.net stuff
(winforms, console apps, etc).
(this comment for future readers more than you, since you're doing asp.net)







John Devlon said:
Thanx Mark,

I didn't know that.... Better to store the data somewhere else then....

John
 
Back
Top