Error when running ASP.NET MVC application from Visual Studio: 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. Stop inventing painful hacks, solution is here.
How to reproduce
This is what I have to do to get this error in Visual Studio:
- Enable building of views in project file
- Switch to release mode
- Build and publish application
- Switch to debug mode
- Run application
What I understood when looking for solution to this issue is that it comes when building of views is enabled.
Before doing anything else try out working solution by Igor Kitsula. Although it is written for Visual Studio 2013 it works also with newer version (I have Visual Studio 2017). In short, this is solution.
- Unload problematic project in Visual Studio
- Open project file and go to end of file
- Paste the following block of XML
<!-- Remove obj folder -->
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
<!-- Remove bin folder -->
<RemoveDir Directories="$(BaseOutputPath)" />
- Save project file and close it
- Reload project and run it
Although most of my new projects are on ASP.NET Core I will leave this peace of information here for records.