Solved

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

Posted on 2008-10-14
9
686 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 59

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

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!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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