John Lam 1997 — 2026

Virtual Directories and Visual Studio .NET

I’m updating the labs for my Programming ASP.NET class that I’m delivering to a bunch of Microsoft developers at their Silicon Valley campus next week. One of the interesting issues that I ran into before (and just re-discovered) is a funny dependency on directory names exhibited by Visual Studio .NET.

The lab series in the course is designed in such a way that I dynamically remap a virtual directory on IIS to a physical directory that contains all of the labs. This way there’s a simple naming convention for all of the labs: http://localhost/labs/. This lets me control global settings for all of the labs using a web.config file that lives in the /labs directory. This is extremely useful in cases where developers must run the labs on a different environment than you’re used to.

But here’s the kicker: the virtual directory name and the physical directory name must match exactly if you want to use Visual Studio .NET to create new projects within that virtual directory. If they don’t you’ll get really confusing and unhelpful error messages. This is strictly a Visual Studio .NET issue; the virtual directory mapping works fine even if the two directory names are different. So watch out for this issue if you use this kind of naming convention for your own ASP.NET development.

1 archived reader comment

Pete Magsig (2003-04-19)

I just spent about 4 pig-headed stubborn hours trying to figure out how to get virtual directories to work properly under visual studio. I’ve been through the MSDN, googling everywhere, but to no avail. Finally I stumbled upon this little gem here and my problems are solved. I think I’ll write a bug report to microsoft.