Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-14
9
Medium Priority
?
693 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
Technology Partners: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

715 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