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 3872346
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:54:56+00:00 2026-05-19T21:54:56+00:00

Whats the best way to get a path to .net 2.0 machine.config file, if

  • 0

Whats the best way to get a path to .net 2.0 machine.config file, if the application is running on .net 4.0?

One way would be to do string manipulation and file system access to replace v4.0* with v2.0* in
new ConfigurationFileMap().MachineConfigFilename; and then pass it to ConfigurationManager.OpenMappedMachineConfiguration(new ConfigurationFileMap(<HERE>)). I will resort to this solution if nothing better is available.

  • 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. Editorial Team
    Editorial Team
    2026-05-19T21:54:57+00:00Added an answer on May 19, 2026 at 9:54 pm

    Since I needed the path to machine.config for ASP.NET versions, I didn’t care about all .NET framework paths (e.g. 3 and 3.5 frameworks since they are just extensions of 2.0). I ended up querying HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET registry key and Path value of the framework key. Finally appending config\machine.config to the framework path yielded desired results.

    The method to map ASP.NET runtime to machine.config path would take strings of any format “v2.0”, “2.0.50727.0” or just “v2” and “2”, regex it to either one decimal digit like “2.0” or one first digit if decimal digits were not specified like “2” and get the right value from the registry. Something similar to this:

    
    string runtimeVersion = "2.0";
    string frameworkPath;
    RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\ASP.NET");
    foreach (string childKeyName in regKey.GetSubKeyNames())
    {
       if (Regex.IsMatch(childKeyName, runtimeVersion))
       {
           RegistryKey subKey = regKey.OpenSubKey(childKeyName))
           {
              frameworkPath = (string)subKey.GetValue("Path");
           }
       }
    }
    string machineConfigPath = Path.Combine(frameworkPath, @"config\machine.config");
    string webRootConfigPath = Path.Combine(frameworkPath, @"config\web.config");
    

    Lastly, I pass this configs to WebConfigurationMap (I am using Microsoft.Web.Administration, but you can use it with System.Configuration as well, the code is almost the same):

    
    using (ServerManager manager = new ServerManager())
    {
       Configuration rootWebConfig = manager.GetWebConfiguration(new WebConfigurationMap(machineConfigPath, webRootConfigPath), null);
    }
    
    

    WebConfigurationMap maps configuration to custom machine.config and root web.config (hence null as a second argument in GetWebConfiguration())

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whats the best way to get the current time (HH:MM:SS) using Objective-C. I would
What is the best way to get absolute path to the file inside the
What is the best way to get the physical path to a file in
What RegKey can you get the default browser application's path from? Best way to
whats the best way to get Statistics Web pages by the users visited ?
What would be the best way to get all the products in all the
I'm trying to figure out whats the best way to get checkboxes to properly
What is the best way to get the path from the NSData bookmark object,
What is the best way to get ocropus running on iOS and/or android? I'm
What's the best way to get a string containing a folder name that I

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.