• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3547
  • Last Modified:

An error occurred loading a configuration file: Failed to map the path '/'.

I recently upgraded from Windows Vista to Windows 7 and from IE 7 to IE 8

This is where the error occurs when trying to debug in local mode:

System.Configuration.Configuration rootWebConfig =
            System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/StockPro");

Any ideas?

Thanks,
0
Dovberman
Asked:
Dovberman
  • 12
  • 11
1 Solution
 
cyrusjoudiehCommented:
public static string GetPhysicalFilePath(string filePath)
{
filePath = filePath.Replace("/", "\\");
if (Path.EndsWith("\\") && filePath.StartsWith("\\"))
filePath = filePath.Substring(1);
return (Path + (Path.EndsWith("\\") ? String.Empty : "\\") + filePath + (filePath.Length > 0 ? (filePath.EndsWith("\\") ? String.Empty : "\\") : String.Empty));
}
System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(App.GetPhysicalFilePath("StockPro"));
 
0
 
cyrusjoudiehCommented:
continue...
forgot to include the Path variable.
public static string Path = HttpContext.Current.Request.PhysicalApplicationPath;
0
 
DovbermanAuthor Commented:
What does this mean?

System.Configuration.Configuration rootWebConfig =
            System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(App.GetPhysicalFilePath("StockPro"));

Error      1      The name 'App' does not exist in the current context      C:\Develop\Apps\StockPro\Default.aspx.cs      48      83      C:\...\StockPro\

           
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DovbermanAuthor Commented:
Perhaps more of the code would be helpful:

public partial class _Default : System.Web.UI.Page
{
    public System.Configuration.ConnectionStringSettings connString;
    public System.Configuration.ConnectionStringSettings connStringMember;

    public int intDays = 0;
    public string strUserName = "";
    public MembershipUser currentUser;
 
    public string strConnection;
    public string strConnectionMember;
    public string strUserID = "";

    public static string GetPhysicalFilePath(string filePath)
    {
        filePath = filePath.Replace("/", "\\");
        if (Path.EndsWith("\\") && filePath.StartsWith("\\"))
            filePath = filePath.Substring(1);
        return (Path + (Path.EndsWith("\\") ? String.Empty : "\\") + filePath + (filePath.Length > 0 ? (filePath.EndsWith("\\") ? String.Empty : "\\") : String.Empty));
    }

    public static string Path = HttpContext.Current.Request.PhysicalApplicationPath;

   
    protected void Page_Load(object sender, EventArgs e)
    {
        //System.Configuration.Configuration rootWebConfig =
        //    System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/StockPro");

        System.Configuration.Configuration rootWebConfig =
            System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(App.GetPhysicalFilePath("StockPro"));
           

0
 
cyrusjoudiehCommented:
try using this:

System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null, null, "StockPro");
0
 
DovbermanAuthor Commented:
This gives me null connection strings.

my app worked perfectly until I upgraded from Windows Vista to Windows 7, and from IE 7 to IE 8.
0
 
cyrusjoudiehCommented:
Usually I use this method for reading the configuration.
WebConfigSettingsEnum : I use it to define the key names. For ease of access in function.

<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="EnableDoubleWindowCheck" value="0"></add>
<add key="AutoLoginRememberMe" value="1"></add>
..............
Just call it like:
string Value = App.WebConfig.ReadKey(App.WebConfig.WebConfigSettingsEnum.AutoLoginRememberMe);


sample code:

public static bool AutoLoginRemeberMe
{
get
{
return App.WebConfig.ReadKey(App.WebConfig.WebConfigSettingsEnum.AutoLoginRememberMe) == "1";
}
}

public static class WebConfig
{
public enum WebConfigSettingsEnum
{
Redirect = 1,
EnableErrorLog = 2,
EnableDoubleWindowCheck = 3,
AutoLoginRememberMe = 4
}
public static string ReadKey(WebConfigSettingsEnum Enum)
{
string Value = ConfigurationManager.AppSettings[Enum.ToString()];
return Value != null ? Value : String.Empty;
}
}
 _______________________________________________________________
Regarding the App class, you can ignore/remove the "App" which referes to a static class which I missed to post it earlier.
If you insist calling it through the App class (App.GetPhysicalFilePath("Folder"))  then you need to define it as static App class like in the code below:
public partial class Default : System.Web.UI.Page
{

protected void Page_Init(object sender, EventArgs e)
{
System.Configuration.Configuration rootWebConfig  =  System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(App.GetPhysicalFilePath("StockPro"));
}

public static class App
{
     public static string Path = HttpContext.Current.Request.PhysicalApplicationPath;
      public static string GetPhysicalFilePath(string filePath)
      {
            filePath = filePath.Replace("/", "\\");
            if (Path.EndsWith("\\") && filePath.StartsWith("\\"))
            filePath = filePath.Substring(1);
            return (Path + (Path.EndsWith("\\") ? String.Empty : "\\") + filePath + (filePath.Length > 0 ? (filePath.EndsWith("\\") ? String.Empty : "\\") : String.Empty));
      }
}

}
0
 
cyrusjoudiehCommented:
if your webconfig is located in the root folder only of the application then you only need to do is to send a null parameter.
which will be:

System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
 
0
 
DovbermanAuthor Commented:
This is more complicated than I thought. I will try to figure it out.

The app worked before I upgraded.
0
 
cyrusjoudiehCommented:
it will work, there is no special case about the operating system. Could be the framwork version changed since you upgraded.
define the connection string under AppSettings as
<add key="Dsn" value="data source=127.0.0.1;initial catalog=database;user id=username;password=password"/>
to read the key:

string DSN = ConfigurationManager.AppSettings["Dsn"];
you can trap the case if the key is null like the function above "ReadKey"
 
0
 
DovbermanAuthor Commented:
Thanks,

I willl spend time with this tomorrow.

David
0
 
DovbermanAuthor Commented:
The app works fine remotely. It fails only when trying to open locally. I need to look at my IIS installation and Cassini.
0
 
cyrusjoudiehCommented:
Actually if the folder resides outside the wwwroot folder make sure that the user IUSER_xxxxx has access identical to the ones in wwwroot .
It depends how your application is set, Virtual folder or as a new website.
Its better to have it standalone as a new website you can change the bindings of each website you have.
Web.config should exist only in the root directory of the website, if you are having a virtual folder you can't have the web.config working there.
example:
Default Webiste: http://localhost/ point to inetpub/wwwrooot

either publish your application under wwwroot or create another folder
under Intepub which will look like this scheme
Inetpub
--MyNewWebsite
--wwwroot

1- Create the folder
2- Add the IUSER_XXXX on MyNewWebsite folder.
3- Create the new website in the IIS and point it to the inetpub/MyNewWebsite
4- Configure the binding which should listen on port number, can be 82 it will be like http://localhost:82/
5- Publish your application into the new folder MyNewWebsite (If you faced problems publishing into your new folder make sure the user owner has full access)
Access your application by browsing into http://localhost:XX/
if you set the binding to 80 then there is no need to specify the port number after localhost
0
 
DovbermanAuthor Commented:
Problem solved. VS should be set to run as administrator.

http://cs.rthand.com/blogs/blog_with_righthand/archive/2007/12/01/WebConfigurationManager.OpenWebConfiguration-throws-Failed-to-map-the-path-_27002F0027002E00_.aspx

Right click the VS desktop icon.
Select the Compatibility Tab.
In the Privilege Level section, Check "Run this program as administrator".

Thanks for all your effort.
0
 
cyrusjoudiehCommented:
this is a work around and not a solution, it means you don't have the correct permissions in your folders of your IIS , you should run VS in Normal Mode without the Admin Rights.
0
 
cyrusjoudiehCommented:
Visual Studio has its own WebService for debugging.
Visual Studio Projects should be in normal folders with current user rights. Check your folders and inherit them to subfolders as shown in the pictures attached (3 pictures).

You can see the IIS_User permissions of the folder where the project is published to, this is a standalone website. (1 picture)

AP.PNG
AP2.PNG
AP3.PNG
IIS.PNG
0
 
DovbermanAuthor Commented:
Please reopen and give all points to cyrusjoudieh.

Thanks,

Dovberman
0
 
cyrusjoudiehCommented:
I found the solution that will make it run without the need of Administrator privilege.
  1. Right Click on the Solution and choose Properties Window
  2. In the Properties Window change the Virtual Path in to / as show in the picture attached
  3. Run the project it should be something like http://localhost:port/
    it should work
Paste the attached code into an ASPX file and execute it, you should get the connection strings in the page if set in web.config.
Good Luck!

<%@ Page Language="C#" AutoEventWireup="true" %>


<script type="text/C#"  runat="server">

    protected void Page_Init(object sender, EventArgs e)
    {

        System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/StockPro");

        System.Configuration.ConnectionStringSettings connString;
        if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0)
        {
            connString = rootWebConfig.ConnectionStrings.ConnectionStrings["NorthwindConnectionString"];
            if (connString != null)
                Response.Write("Northwind connection string = \"" + connString.ConnectionString + "\"");
            else
                Response.Write("No Northwind connection string");
        }
    }
</script>

Open in new window

Prop.PNG
VP.PNG
0
 
DovbermanAuthor Commented:
Please reopen. New solutions that work have been presented.
0
 
DovbermanAuthor Commented:
I do not have the Property option.

I am the only user of the development computer. therefore I can always run as administrator.

Thanks,


Property-Menu.jpg
0
 
DovbermanAuthor Commented:
I will leave the app as is. The connections are recognized.


 protected void Page_Load(object sender, EventArgs e)
    {
        System.Configuration.Configuration rootWebConfig =
            System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/StockPro");

        if (0 < rootWebConfig.ConnectionStrings.ConnectionStrings.Count)
        {
            connString =
                rootWebConfig.ConnectionStrings.ConnectionStrings["ConStockSelect"];
            connStringMember= 
                rootWebConfig.ConnectionStrings.ConnectionStrings["MemberShipSQLConnectionString"];
            
            if (null != connString)
                Console.WriteLine("StockPro connection string = \"{0}\"",
      
              connString.ConnectionString);
            else
                Console.WriteLine("No StockPro connection string");
        }

        // Define the ADO.NET Connection object.
        string strConnection = connString.ToString();
        SqlConnection conStockSelect = new SqlConnection(strConnection);
        conStockSelect.Open();

        string strIPAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        
        string  strUserName = User.Identity.Name;
        MembershipUser currentUser = Membership.GetUser(strUserName);
        
    
        if (User.Identity.IsAuthenticated)
        {
            lblWelcome.Text = "Welcome " + strUserName;
            
            
            // Get subscription renewal date
            string strUserID = currentUser.ProviderUserKey.ToString();
            string strRenewSQL = "SELECT TOP 1 UserID,DATEADD(m, 1, SubscriptionDate) AS RenewDate  ";
            strRenewSQL += ", SubscriptionDate FROM Subscriptions ";
            strRenewSQL += "WHERE UserID = '" + strUserID + "' ";
            strRenewSQL += "ORDER BY SubscriptionDate DESC";

            string strRenewDate = GetColValue(conStockSelect, strRenewSQL, "RenewDate");
            if (strRenewDate == "None")
            {
                // Not a subscriber
                lblExpired.Text = strUserName + " does not subscribe";
                return;
            }

Open in new window

0
 
DovbermanAuthor Commented:
Thank you.
0
 
cyrusjoudiehCommented:
Yes, it seems you have a web application and not a webiste solution.
To acheive this, you need to right click on the web application and choose properties then navigate to the third tab on your left "web" and check the virtual path to be /.
Also attached the page after the "Start Debugging" was executed.
VS was running without Admin privileges.

 
You are welcome!

WebApplication.PNG
Result.PNG
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 12
  • 11
Tackle projects and never again get stuck behind a technical roadblock.
Join Now