WebConfigurationManager.OpenWebConfiguration throws Failed to map the path '/'.

by Miha Markič 1. December 2007 20:30

Create a ASP.NET Web Site and put this piece of code into Page_Load method:

Configuration cfg = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);

There are good chances you'll get Failed to map the path '/'. exception. The error is a peculiar one, even more so because the code is straight from the MSDN documentation. It happened to me when I've upgraded my ASP.NET Web Site Visual Studio 2005 project to 2008 (still targeting .net 2.0 framework) one.

After scratching my head for a while and googling around I've found the solution: run Visual Studio as administrator. Right, I've set my Visual Studio 2005 to run always as administrator and thus it worked before. After upgrading to Visual Studio 2008 the problem began to manifest - because I haven't yet set Visual Studio 2008 to run as administrator by default nor did I run it as administrator explicitly. So, to make it work you should run Visual Studio as administrator. Which is a problem because many people would use administrator privileges when developing (i.e. writing into Program Files folder - don't do it!). And when they'll deploy application to normal users it will throw exceptions one after the another.

So, be cautious when you are developing under administrator privileges.

UPDATE: I run Vista x86 OS. Not sure, but the same problem might be happening on XP/2003, too.

Tags:

Comments (2) -

Niko
Niko
12/3/2007 11:03:54 AM #

I guess this is the case for Vista users?

Reply

Miha Markic
Miha Markic
12/3/2007 11:38:32 AM #

Hi Niko,

Yes, it happened to me on Vista. However, it might be happening on XP/2003, too.

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Miha Markic

About me
Righthand
 
Microsoft MVP
 
Developer Express' DXSquad
INETA Country Leader for Slovenia
INETA Country Leader for Slovenia

Slovene Developer Users Group Lead
Friends of Red-Gate
LLBLGenPro Partner

Miha currently works as a free lance consultant and software developer specialized in .net area.
He graduated in Computer and information science at the University of Ljubljana, Slovenia. He has accumulated experience in various programming languages such as Java, Visual Basic 3-6 (MCP), Visual C++, Delphi, C# and VB.Net through years.
He has experience in practically all (technical) stages of project development, including planning, framework development, user interface, business processes, as well as testing and documenting. He has worked on big and small projects in Slovenia and abroad (e.g. participated in completing level 3 IS for the Nucor steel plant, Hertford, USA).
Currently he enjoys programming in .net environment using C#. Since 2000 he has been active in Developer Express' DX Squad and has been ECDL trainer and tester. He also gives lectures on conferences and other events in Slovenia.

Month List

Tag cloud

Most comments

Paulius Paulius
1 comments
us United States
Meh Meh
1 comments
us United States
bart dm bart dm
1 comments
nl Netherlands

RecentComments

Comment RSS