What is a Virtual Directory and how to create it?


What is a virtual directory ?

A virtual directory represents a web application and it points to a physical folder in your computer.

A web application is accessed using a virtual directory name instead of a physical folder name. For example, if you have a web application called "Shopcart" in your machine, you will have a virtual directory for this web application. You will access your web application using the URL httP://localhost/Shopcart. If your virtaul directory name is "Test", then your web application url will be "http://localhost/Test".

Assume you have a web application called "Shopcart", created under the physical folder "C:\MyProjects\Shopcart".

You can go to IIS and see this virtual directory listed. Right click on this virtual directory name in IIS and see the properties. You can see that this virtual directory is pointing to the physical location "C:\MyProjects\Shopcart".

If you have a file called "File1.aspx" under the folder "C:\MyProjects\Shopcart\", then you can access this file using Internet Explorer with the URL "http://localhost/Shopcart/File1.aspx"

How to create a virtual directory ?

When you create a new web project using, a new virtual directory will be created automatically for you. This virtual directory will point to a new folder created under C:\Inetpub\wwwroot.

If you like to better organize your projects and files in your favourite folder, you must manually create a new folder for each project in your preferred location and convert it into a virtual folder manually.

There are couple of ways you can do this.