473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Web.Config & common code snippets.

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
6 1583
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Suresh Gladstone | last post by:
Hi, This is a bit with versioning and installation of the .NET dlls. I want to perform the following, 1. A third party application will be invoking my .NET dll through COM interop . For this I...
2
by: Richard | last post by:
Hi, I'm having trouble setting up a config file based trace switch & listener. I added an application config file to my console based C# program using the "Add New Application Config File" button...
0
by: jOs | last post by:
C#B - SHARED SOURCE PROJECT FOR A C# Browser Let's sort this stuff out once and for ALL. =============================================================== Anyone who's having problems in...
4
by: Dominic | last post by:
Suppose I have a web.config. I'd like to move some configuration settings from this web.config and put it another XML file (say, common.xml). Now, is there any way that I can modify the web.config...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
26
by: Robert Baer | last post by:
The following passes the test as valid, and the mouseover for the six indicated areas also work. I need various areas to link to another page, including the six mentioned. However either the MAP...
8
by: aabdis | last post by:
Hello All.... I have a question... i have two Windows apps (one UI, and one service) which use a common DLL that hands out database results and such to the two apps. The DLL always connects to...
1
by: Nathan Sokalski | last post by:
When implementing an interface in VB.NET using Visual Studio .NET 2005, it would be nice if I could have the method/function headers inserted automatically. Whenever we implement an event (such as...
1
by: MasterLalit | last post by:
Hi, i am using a app.config file in my console application. App.config code--> <configuration> <configSections> <section name="enterpriseLibrary.ConfigurationSource"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.