By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,795 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,795 IT Pros & Developers. It's quick & easy.

Web.Config & common code snippets.

P: n/a
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.

Feb 7 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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@nospam.comwrote in message
news:02**********************************@microsof t.com...
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.

Feb 7 '07 #2

P: n/a
G
"Bhaskardeep Khaund" <bh*********@rediffmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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.

Feb 7 '07 #3

P: n/a
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" <g@nospam.comwrote in message
news:3E**********************************@microsof t.com...
"Bhaskardeep Khaund" <bh*********@rediffmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>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.

Feb 7 '07 #4

P: n/a
G

"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:SI******************************@eclipse.net. uk...
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.

Feb 7 '07 #5

P: n/a
by app pool I meant to say application object :)

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"G" <g@nospam.comwrote in message
news:AB**********************************@microsof t.com...
>
"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:SI******************************@eclipse.net. uk...
>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.

Feb 7 '07 #6

P: n/a
G

"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:fP*********************@eclipse.net.uk...
by app pool I meant to say application object :)

Regards

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

Cheers! :)

G.

Feb 7 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.