Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

ASP.NET MVC Error

DZone's Guide to

ASP.NET MVC Error

If you've seen this error - 'It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level' - the solution is here.

· Web Dev Zone ·
Free Resource

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

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, the solution is here.

How to Reproduce This Error

This is what I have to do to get this error in Visual Studio:

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

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

Solution

Before we doing anything else, let's try out a working solution by Igor Kitsula. Although it is written for Visual Studio 2013, it also works with newer versions (I have Visual Studio 2017). In short, this is the solution.

  1. Unload the problematic project in Visual Studio.
  2. Open the project file and go to the end of the 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 the project and run it.

Although most of my new projects are on ASP.NET Core, I will leave this piece of information here for the record.

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

Topics:
asp.net mvc ,xml ,visual studio ,web dev ,asp.net mvc error

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}