Web.Config & common code snippets.

G

G

Hello,

Is it possible (and / or wise) to add custom pieces of code inside your
Web.Config file? For example I store the connection string in Web.Config
and access it via ConfigurationSettings.AppSettings["ConnectionString"]. Is
it possible to call on ConfigurationSettings.AppSettings["MyCustomString"]
which pulls back my stored string?

For example can I add this in Web.Config:

<add key="Author" value="All articles on this site written by Inspector
Gadget & associates" />

And then from my in my code behind file

lblPageFooter.text = ConfigurationSettings.AppSettings["Author"]

Would there be any benifit doing this?

G.
 
B

Bhaskardeep Khaund

Hi,

Yes you can do that......AppSetting just stores a set of Key-Value strings,
which you can request as ConfigurationSettings.AppSettings[name of the key]

Rgds,
Bhaskar
 
G

G

Bhaskardeep Khaund said:
Hi,

Yes you can do that......AppSetting just stores a set of Key-Value
strings, which you can request as ConfigurationSettings.AppSettings[name
of the key]

Rgds,
Bhaskar


Thanks. Does it use memory even if I choose not to call on the strings? If
I have 5,000 simultaneous users, would I have used the memory for each user
just to have it stored in Web.Config, or would it only load when I requested
it from my code?

Regards,

Gary.
 
J

John Timney \(MVP\)

if I remember correctly, each time you call
ConfigurationSettings.AppSettings[name of the key] it loads all the config
keys into memory, then iterates the collection to get the value. You should
probably store then in web.config and load them into the application pool in
the app onstart event access that from your code instead.

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog



G said:
Bhaskardeep Khaund said:
Hi,

Yes you can do that......AppSetting just stores a set of Key-Value
strings, which you can request as ConfigurationSettings.AppSettings[name
of the key]

Rgds,
Bhaskar


Thanks. Does it use memory even if I choose not to call on the strings?
If I have 5,000 simultaneous users, would I have used the memory for each
user just to have it stored in Web.Config, or would it only load when I
requested it from my code?

Regards,

Gary.
 
G

G

John Timney (MVP) said:
if I remember correctly, each time you call
ConfigurationSettings.AppSettings[name of the key] it loads all the config
keys into memory, then iterates the collection to get the value. You
should probably store then in web.config and load them into the
application pool in the app onstart event access that from your code
instead.


Thanks I will read up on the App Pool and App Onstart, new to all this :)

G.
 
J

John Timney \(MVP\)

by app pool I meant to say application object :)

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog


G said:
John Timney (MVP) said:
if I remember correctly, each time you call
ConfigurationSettings.AppSettings[name of the key] it loads all the
config keys into memory, then iterates the collection to get the value.
You should probably store then in web.config and load them into the
application pool in the app onstart event access that from your code
instead.


Thanks I will read up on the App Pool and App Onstart, new to all this :)

G.
 

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

Top