Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ex = {"'D:\\PipelineDashboardSource\\PipelineDashboard\\web' is not a valid virtual path."}

Posted on 2008-10-14
9
Medium Priority
?
695 Views
Last Modified: 2012-05-05
i am not getting right path for web.config file.following exception is throwing
ex = {"'D:\\PipelineDashboardSource\\PipelineDashboard\\web' is not a valid virtual path."}

following code i am using to get webconfig path:

string configPath = System.Web.HttpContext.Current.Server.MapPath(@"/web");
0
Comment
Question by:ajay1feb
  • 2
  • 2
  • 2
  • +1
9 Comments
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22712127
Firstly, I think you want this:
string configPath = System.Web.HttpContext.Current.Server.MapPath("/web.config");

When you want to use this string which will then contain \, I would @ quote then but since you are using forward slash (relative path) I don't think that is necessary.
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22712236
Your code is exprecting a virtual directory path something like http://myserver/virtualdir/web.config
Server.MapPath method will give you the location of a file in the machine something like D:\myfolder\web.config

What you can do is, Get the URL of the page from current context and replace the file name with web.config if both page and web.config files are in same folder. Otherwise get the server name from current context and construct path of web.config


0
 

Author Comment

by:ajay1feb
ID: 22712567
when i tried following code it is still giving same error.

string configPath = System.Web.HttpContext.Current.Server.MapPath("/web.config");


// Get the Web application configuration object.
// i am getting error on following line
Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:TechTiger007
ID: 22712777
Its giving error because you are still using Server.MapPath which will give the location of the file in the hard disk where in the application is expecting virtual path as I explained before.

Try something like this

string configPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath.Replace("Home.aspx","web.config");// Server.MapPath(@"/web");
        Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(configPath);
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22713060
Try the attached code snippet..
For details:http://msdn.microsoft.com/en-us/library/ms151451(VS.80).aspx

WebConfigurationFileMap fileMap CreateFileMap();
System.Configuration.Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(fileMap,"/config");

Open in new window

0
 

Author Comment

by:ajay1feb
ID: 22738804
dear prairiedog,

  when i am working with development server it is giving right path of web.config file but whenever i start working with iis then it is not getting web.config file which is on server, in this case it is taking machine.config file i belive.can you tell me what is code for getting web.config file on web server not on development server.

Regards,
ajay
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 2000 total points
ID: 22741879
Try this code snippet. It will write out the first connection string in your current web.config:
WebConfigurationFileMap fileMap = new WebConfigurationFileMap();
            string physDir = Server.MapPath(Request.ApplicationPath);
 
            VirtualDirectoryMapping vDirMapBase = new VirtualDirectoryMapping(physDir, true, "web.config");
            fileMap.VirtualDirectories.Add("/", vDirMapBase);
            
            System.Configuration.Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(fileMap, "/config");
            Response.Write("Connection string: " + config.ConnectionStrings.ConnectionStrings[0]);

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question