Avatar of Dinesh Kumar
Dinesh Kumar
Flag for India asked on

c# Solution when keys in web.config can increase

Hi Experts,

I can have any number of following keys in web.config

<add key="WebServer1Logs" value="C:\meetDinesh"/>
<add key="WebServer2Logs" value="C:\meetDinesh"/>
<add key="WebServer3Logs" value="C:\meetDinesh"/>
<add key="WebServer4Logs" value="C:\meetDinesh"/>

The key format will remain same i.e. next will be WebServer5Logs

I want to read every key using some way so if more keys are added in future, I don't need to change the c# code to read them.

I believe this can be done with Regex can you share that regex.

or some other way also exists.
C#ASP.NETRegular Expressions

Avatar of undefined
Last Comment
Dinesh Kumar

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Lokesh B R

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dinesh Kumar

ASKER
1. cause the keys should be known at compile time  can you explain it more.

2. instead of writing so much code as you mentioned, Don't you think I can apply the regex on Webconfig
    only thing the worry is web.config at Server may be not available for READ when site goes live.
SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Dinesh Kumar

ASKER
Thanks ste5an..
Dinesh Kumar

ASKER
this task is deferred to future so will need time to respond on this.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Dinesh Kumar

ASKER
Thanks Experts for your valuable time and answers.