Solved

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

Posted on 2008-10-14
9
690 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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.

 
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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

617 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