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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:25:23+00:00 2026-05-12T08:25:23+00:00

I am looking to redirect the standard .Net ConfigurationManager class to another file; entirely

  • 0

I am looking to redirect the standard .Net ConfigurationManager class to another file; entirely. The path is determined at runtime so I can’t use configSource or such (this is not a duplicate question – I have looked at the others).

I am essentially trying to duplicate what ASP.Net is doing behind the covers. Thus not only my classes should read from the new config file, but also any standard .Net stuff (the one I am specifically trying to get to work is the system.codeDom element).

I have cracked open Reflector and started looking at how ASP.Net does it – it’s pretty hairy and completely undocumented. I was hoping someone else has reverse-engineered the process. Not necessarily looking for a complete solution (would be nice) but merely documentation.

  • 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-12T08:25:23+00:00Added an answer on May 12, 2026 at 8:25 am

    I finally figured it out. There is a public documented means to do this – but it’s hidden away in the depths of the .Net framework. Changing your own config file requires reflection (to do no more than refresh the ConfigurationManager); but it is possible to alter the configuration file of an AppDomain that you create via public APIs.

    No thanks to the Microsoft Connect feature I submitted, here is the code:

    class Program
    {
        static void Main(string[] args)
        {
            // Setup information for the new appdomain.
            AppDomainSetup setup = new AppDomainSetup();
            setup.ConfigurationFile = "C:\\my.config";
    
            // Create the new appdomain with the new config.
            AppDomain d2 = AppDomain.CreateDomain("customDomain", AppDomain.CurrentDomain.Evidence, setup);
    
            // Call the write config method in that appdomain.
            CrossAppDomainDelegate del = new CrossAppDomainDelegate(WriteConfig);
            d2.DoCallBack(del);
    
            // Call the write config in our appdomain.
            WriteConfig();
    
            Console.ReadLine();
        }
    
        static void WriteConfig()
        {
            // Get our config file.
            Configuration c = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    
            // Write it out.
            Console.WriteLine("{0}: {1}", AppDomain.CurrentDomain.FriendlyName, c.FilePath);
        }
    }
    

    Output:

    customDomain: C:\my.config
    InternalConfigTest.vshost.exe: D:\Profile\...\InternalConfigTest.vshost.exe.config
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for fast methods/ways I can redirect a HTML page to another
I'm looking to redirect a user to a static form so they can review
I am looking to use rails to redirect links that I am sure are
I'm looking for a way to redirect output in a groovy script to stderr:
I am looking to create a 301 redirect based purely on a query string
I am looking for a way to redirect a domain to its subdomain via
I'm looking at a web application with a Response.Redirect between two Https pages. I
Looking for C# class which wraps calls to do the following: read and write
I'm looking for a way to rewrite URLs only if the path doesn't exist.
I'm looking for an example of redirecting stdout to a file using Perl. I'm

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.