Retrieve multiple values in web.config file

Posted by Venkatesh under ASP.NET on 3/3/2011 | Points: 10 | Views : 4514 | Status : [Member] | Replies : 7
Hi,

in Web.config file i mentioned same key in appsettings.And how to retrieve these values

ex:<add key="First" value="dotnet"/>
<add key="First" value="dotnetfunda"/>

how to retrieve these two values

Thanks & Regards
Venkatesh




Responses

Posted by: Raja on: 3/3/2011 [Member] Starter | Points: 25

Up
0
Down
Strange, why to keep two appsettings with same key and same value?

What is the benefit of it and what you are achieving it?

Regards,
Raja, USA

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Venkatesh on: 3/3/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

This is asked in interview.

Thanks & Regards
Venkatesh

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 3/3/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Even though you specify multiple appsettings keys with same name in a web.config file the last one will be considered and rest all will be ignored. So in your case if you search by your key name First you will get the value as dotnetfunda as result.

Thanks and Regards
Madhu

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/3/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi venkatesh,

I have a question here, if the interview question is like this. Does the same key value pair is available in Parent Web.config and also in Child web.config with different values? Or in the same Web.Config with same key and different value?

If its in the same Web.Config i hope it should not work. If its in Parent and Child then it will fetch the value from Child config

Thanks
Karthik
www.f5Debug.net

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 3/4/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi karthik,

If its in the same Web.Config then it does work but the last one i mean the bottom one will be considered and rest all will be ignored.

if we give this

<add key="First" value="dotnet"/> // Ignored
<add key="First" value="dotnetfunda"/> //Considered





Thanks and Regards
Madhu

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Venkatesh on: 3/4/2011 [Member] Starter | Points: 25

Up
0
Down
Hi madhu

Its correct but its fetching second value So, how to retreive first value

Thanks & Regards
Venkatesh

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/4/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Ok thanks madhu and venkatesh...

Thanks
Karthik
www.f5Debug.net

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response