What's the difference between Web App and Virtual Folder in the context of IIS 7.x?

As I deploy my web site, I found that I could convert a folder into a virtual folder or web application, I am totally confused about these 2 concepts.

  • Why there are two different types?

  • What's the purpose of each?


A Virtual Folder or Virtual Directory is just a link to a physical folder somewhere on the server. This folder becomes part of the website structure and you can use the virtual directory in the path part of URLs. Code that executes in Virtual Directories will execute in the same "Application" as it's parent.

An Application is where the code that runs inside that "folder" has it's own Session state and Application state. It is in effect a new standalone application living underneath the root application.

For example, if you were to deploy an ASP.NET application into a site that had an Application folder called /myapp then that application would have it's own application domain, session state, application state completely separate from another ASP.NET application running in /. For example: if you set an Application value Application["Thing"] = 123 in the root application and then did the same but with a different value in /myapp then Application["Thing"] in the root would not be overwritten by the assignment in /myapp.

Another thing you can do with Application's is specify a different Application Pool to run under. For example your root / application might contain an ASP.NET 2.0 application and run in a pool configured for .NET 2.0. However you may want to run a blog or forum application written in ASP.NET 4.0. Now because you can't mix ASP.NET runtime versions in the same application pool, you can specify an alternative application pool specifically for ASP.NET 4.0 applications.

Applications can also behave like Virtual Directories and you can point an application folder at a physical folder elsewhere on the server.

If you're interested in the underlying mechanics of Virtual Directories and Applications on IIS7 then have a look at this answer I posted a while back:

Using ServerManager to create Application within Application


To add an informational detail to what Kev has very nicely mentioned - All virtual directories by default run under a pre-defined app pool named DefaultAppPool. DefaultAppPool comes by default with IIS whenever you enable this feature in windows. For WebApps you can always create fresh/new appPools and run your webApp inside your newly created appPool. These appPools provide you that physical/separate process space (in form of worker processes) with the help of which IIS is able to provide services like sessions state, application state etc in silos to a webApp when it has its own appPool defined. Whenever your webApp's appPool crashes, the other webApps (using their own custom appPool) or virtual directories (using DefaultAppPool appPool) remain completely unaffected.