TODO:
You open a website in Visual Studio, and get the dreaded "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS" error message.
SOLUTION:
1. Make sure you opened the site and not the parent folder.
2. In my case, I created a folder called "backup", and copied my entire site to it. Therefore, when I opened the site, that folder was loaded, and it too had a Web.Config file in it (since this folder contained a complete site backup). Simple remove that Web.Config and you will be set.
example showing my problematic folder structure:
root
Web.Config
site folder 1
site folder 2
backup
Web.Config
site folder 1
site folder 2
NOTES:
The presence of the backup folder in red is the culprit. It contained a backup copy of the root web.config, which contained entries only allowed in the root level Web.Config.