Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 124085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:23:22+00:00 2026-05-11T04:23:22+00:00

Currently in my ASP.Net applications web.config I have an application setting that stores a

  • 0

Currently in my ASP.Net applications web.config I have an application setting that stores a comma delimited list of mapping values, like the one below. In the code behind I need to perform a lookup on this data based on input values 1, 2, 3 etc. I can either string split it and loop until I find a match, or use Regex to pull the value from the config string.

Currently i’m using Regex to get the mapping value. I’m not opposed to changing how the data is stored in the web.config. Is there a more simple and elegant way of handling this?

<add key='Mappings' value='1|APP,2|TRG,3|KPK,4|KWT,5|CUT' /> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T04:23:23+00:00Added an answer on May 11, 2026 at 4:23 am

    If you need to use this lookup frequently and the string in web.config doesn’t change very often, then it makes sense to parse the string once into a Dictionary object and store that in the Application or Cache.

    Lookups from the Dictionary will be lightning fast, especially compared to parsing the string each time.

    private static readonly object _MappingsLock = new object();  public static string GetMapping(int id) {     // lock to avoid race conditions     lock (_MappingsLock)     {         // try to get the dictionary from the application object         Dictionary<int, string> mappingsDictionary =             (Dictionary<int, string>)Application['MappingsDictionary'];          if (mappingsDictionary == null)         {             // the dictionary wasn't found in the application object             // so we'll create it from the string in web.config             mappingsDictionary = new Dictionary<int, string>();              foreach (string s in mappingsStringFromWebConfig.Split(','))             {                 string[] a = s.Split('|');                 mappingsDictionary.Add(int.Parse(a[0]), a[1]);             }              // store the dictionary in the application object             // next time around we won't need to recreate it             Application['MappingsDictionary'] = mappingsDictionary;         }          // now do the lookup in the dictionary         return mappingsDictionary[id];     } }  // eg, get the mapping for id 4 string mapping = GetMapping(4);  // returns 'KWT' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have VS2005 and I am currently trying to debug an ASP.net web application.
I'm currently working on web application using VB in ASP.NET. Right now I have
I am currently working on an web application that uses ASP.NET 2.0 framework. I
I have an ASP.NET web forms application that requires that requires that a user
I currently have an asp.net website hosted on two web servers that sit behind
Let's say, for the sake of argument, that I have 30 asp.net web applications
I have an ASP.NET web application that calls a .NET DLL, that in turn
I have an ASP.NET web form application that on the server side I need
I have an ASP.NET MVC 3 application with the following web.config settings. <authentication mode=Forms>
I have just re-implemented an ASP.NET web application that uses NHibernate to use a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.