[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

How does ConfigurationManager.AppSettings.Set stores values?

Natasha

3/5/2006 9:14:00 PM

Hello everybody,
you can use ConfigurationManager.AppSettings.Set method
(ConfigurationManager is in System.Web.Configuration namespace) to store a
modified value from web.config.
To be practical, you define a custom key in web.config:

<appSettings>
<add key="ReportButtonClick" value="0" />
</appSettings>

retrieve value of the key with Get method:

counter = ConfigurationManager.AppSettings.Get("ReportButtonClick")

modify this value:

counter = counter + 1

and write it back with Set method:

ConfigurationManager.AppSettings.Set("ReportButtonClick", counter)

If I access back value with Get method, I find modified value but, of
course, web.config is NOT modified.
Where does Set method stores property's value?
1 Answer

Alvin Bruney [ASP.NET MVP]

3/6/2006 6:26:00 PM

0

it's an in-memory story. If you need it to actually modify the value inside
the config file, use one of the xml file objects to add the appropriate
value to the config. This is not a recommended approach by the way, but it
is a valid one.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



"natasha" <natasha@discussions.microsoft.com> wrote in message
news:0E4D7527-C2B5-444B-AFAF-866B11B706FE@microsoft.com...
> Hello everybody,
> you can use ConfigurationManager.AppSettings.Set method
> (ConfigurationManager is in System.Web.Configuration namespace) to store a
> modified value from web.config.
> To be practical, you define a custom key in web.config:
>
> <appSettings>
> <add key="ReportButtonClick" value="0" />
> </appSettings>
>
> retrieve value of the key with Get method:
>
> counter =
ConfigurationManager.AppSettings.Get("ReportButtonClick")
>
> modify this value:
>
> counter = counter + 1
>
> and write it back with Set method:
>
> ConfigurationManager.AppSettings.Set("ReportButtonClick", counter)
>
> If I access back value with Get method, I find modified value but, of
> course, web.config is NOT modified.
> Where does Set method stores property's value?