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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:29:56+00:00 2026-05-23T15:29:56+00:00

OK so we have something that is currently using OpenExeConfiguration for reading a config

  • 0

OK so we have something that is currently using OpenExeConfiguration for reading a config file, however this doesn’t work when running in the web context.

I’ve tried a variety of different ways of opening the web.config programmatically but I can’t seem to get it to read the correct web.config file. In case it matters I am currently debugging it in VS 2008.

1. config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);

2. config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = "web.config" }, ConfigurationUserLevel.None);

3. config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");

4. config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);

5.  System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);

It either opens up the wrong config file (either the machine config, or the VS /IDE/Web.config) or complains about the error:

{System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Failed to map the path ‘/’. —> System.InvalidOperationException: Failed to map the path ‘/’.

Edit –
OK so a combination of

config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");

AND running Visual Studio 2008 As Administrator worked. Am hoping we don’t run into security/permission issues when we deploy to our web server / client environments!

  • 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-23T15:29:57+00:00Added an answer on May 23, 2026 at 3:29 pm

    So in the end I used this code (had to handle whether the web application was running, or if our unit test code was running).

    System.Configuration.Configuration config = null;
    
    if (System.Web.HttpContext.Current != null && !System.Web.HttpContext.Current.Request.PhysicalPath.Equals(string.Empty))
            config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
    else
            config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    

    Also have to be running Visual Studio in Administrator mode – which I found out you can set as a property on your shortcut so you don’t need to remember each time in Windows 7 to right click and run as administrator 🙂

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

Sidebar

Related Questions

I currently have a table structure that looks something like this(some details omitted): ColumnName
I currently have service classes that look something like this public class UserService :
I am currently using a C++ IDE for something that will need to work
We currently have an ant task that contains something similar to the following: <filelist
I have something that looks like this: As you can see, Blambo is a
Is there any way to have something that looks just like a file on
In my code, I have something that looks like this: @implementation MyClass - (id)
I'm currently using the following (web) applications that all need a username / password:
I'm currently using this to detect if the visitors have flash installed or not
I have an Access application that's currently using the fhandlefile() procedure here: http://access.mvps.org/access/api/api0018.htm ...to

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.