ASP.NET MVC error: It is an error to use a section registered as allowDefinition=’MachineToApplication’ beyond application level

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:

  1. Enable building of views in project file
  2. Switch to release mode
  3. Build and publish application
  4. Switch to debug mode
  5. Run application

What I understood when looking for solution to this issue is that it comes when building of views is enabled.

Solution

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.

  1. Unload problematic project in Visual Studio
  2. Open project file and go to end of file
  3. Paste the following block of XML
    <Target Name="BeforeBuild">
      <!-- Remove obj folder -->
      <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
      <!-- Remove bin folder -->
      <RemoveDir Directories="$(BaseOutputPath)" />
    </Target>
  4. Save project file and close it
  5. 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.

Gunnar Peipman

Gunnar Peipman is ASP.NET, Azure and SharePoint fan, Estonian Microsoft user group leader, blogger, conference speaker, teacher, and tech maniac. Since 2008 he is Microsoft MVP specialized on ASP.NET.

    3 thoughts on “ASP.NET MVC error: It is an error to use a section registered as allowDefinition=’MachineToApplication’ beyond application level

    • Pingback:Dew Drop - July 12, 2018 (#2764) - Morning Dew

    • July 25, 2018 at 6:48 am
      Permalink

      String repeat method concept ,I easly understand by ur explain it is to understand ,the difference between methods used in C# program ,while we always go through forloop by ur concept it’s clear that less time to execute the method

    • May 17, 2019 at 5:50 pm
      Permalink

      Thank you very much

    Leave a Reply

    Your email address will not be published. Required fields are marked *