[asp.net] Error: allowDefinition='MachineToApplication' beyond application level

I have downloaded the online project in ASP.Net. While running application I get an error

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.

What changes should i make in web.config or elsewhere to make this work?

This question is related to asp.net visual-studio-2012

The answer is


I was having the same issue when I would publish the site, if I build the site I get no issues but while publishing I would get this awful error:

"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"

I tried everything that has been stated here in this post to no resort, what worked for me was to just create a new publish profile with exactly the same as the one I've been using and that works well, don't get the error with the new profile but do with the old. Not sure what the difference is but at least I can publish my MVC project.

Hope this helps somebody!


None. You need to set up the directory you've placed the website as a web application within IIS.


Clean your project Remove the /obj folder (probably using publish and deploy? - there is a bug in it)


Probably you have a sub asp.net project folder within the project folder which is not configured as virtual directory. Setup the project to run in IIS.


In my case,

Solution contains 6 projects, 1 main and 5 sub directories. all the sub directories having web.config.

When running any page within sub directories, I was getting same error.

I removed this line from web.config,

<authentication mode="Windows"/>

that worked for me.


In my case I was hosting with GoDaddy which wasn't the problem but it added a layer of confusion.

I had a root folder "WebServices" and set that as the application root.

HOWEVER the service was in a subfolder called "GeoLocateSpecials" as the "WebServices" folder is a container for many services.

So I had to set GeoLocateSpecials as an application root and it worked great from there.

Hope that helps anyone else out there.


I have a website project.

In my case I had moved the solution file to another path and that cause the problem. I restored it to the previous location and the problem went out.


I had this error when building the solution with Web Deployment Project created into my solution. I resolve the error by deleting the folder where Web Deployment Project is built to. This folder is specified in "Project Folder" attribute of WDP properties


Apparently there were two web.config files in my solution. I am using MVC4 and there was another config file under Views and i was making the change in the wrong file. Fixed there helped me.

But you can always change the default redirect/route in the global.asax file.


In my case, the problem appeared only after I published the project to the subdirectory. Because of my lack of knowledge, I have placed my web_publish subdirectory inside the web_project directory.

It is clear that the web_publish contains also the same Web.configs that the project contains. However, the web_project does not know that my web_publish should be avoided when searching Web.configs in the nested subdirectories. This way, the Web.configs were duplicated and the error appeared.

The solution was to place my web_publish somewhere else.


Just come across this post and that was happening to me.
Just Clean the project and the error goes away. (must be a VS2010 bug)


The error suggests that the code you are using is expecting a virtual directory to be setup on IIS.

Look up the documentation and add the required virtual directory. It should be a directory that has a web.config in it (not the root directory).


For any one still looking, my solution was to delete both the bin and obj folders and restart visual studio seems to fix it.


My problem was I had accidentally published my webservice to a pre-completed location on a fresh install of VS2010.

I had published to a folder called PreCompiledWeb, and the presence of the web.config I suspect messed it up.

I simply nuked the folder, and refreshed the project.

When double-clicking this error - it took me to that erroneous web.config file, which tipped me off.


This error occurs when you attempt to open a project as a website. The easiest way to determine if you've created a website or a project is to check your solution folder (i.e. where you saved your code) and see if you have a *.sln file in the root directory, if you do then you've created a project.

Just to add, I encountered this error just now when I attempted to open a project I created a while back by selecting "File", "Open Website" from the Visual Studio menus whereas I should have selected "File", "Open Project" instead. I facepalmed as soon as I realised :)


Delete bin and obj folders. Then rebuild the solution.


I have just had this problem when building a second version of my website. It didn't happen when I built it the first time.

I have just deleted the bin and obj folders, run a Clean Solution and built it again, this time without any problem.


I had a project that I didn't want to be a web application I wanted it to be a folder. The answer was to delete the web.config file altogether. It only belongs in the root of an application.


I tried every solution above, but none of them worked for my problem. (I'm sure there are 1000 solutions to this problem) For my scenario, I was attempting to publish my WCF web service that I had in test into production.

However, I failed to realize that in production we are HTTPS only, meaning we redirect everything to HTTPS. As it turns out, I was pointing to the service via HTTP instead of HTTPS, thus causing the error. The solution in this scenario was to simply to change the address protocol to HTTPS rather than HTTP.

I hope that helps some poor soul out there trying to figure out this problem.


I've just encountered this "delight". It seems to present itself just after I've published a web application in release mode.

The only way to consistently get round the issue that I've found is to follow this checklist:

  1. Clean solution whilst your solution is configured in Release mode.
  2. Clean solution whilst your solution is configured in Debug mode.
  3. Build whilst your solution is configured in Debug mode.

In my case there was a "Backup" folder which contained another copy of the whole website in there. This meant another web.config and so the build failed with this error. I deleted the "Backup" folder, did a Clean solution on the Debug and Release builds, and the error disappeared.


if you ever encounter this error

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

SOLUTION
I had the same issue with VS 2012. I resolved this by

  1. Unload your current project
  2. edit your .csproj
  3. Find this <MvcBuildViews>false</MvcBuildViews>
  4. Instead of false change the value to true
  5. Load again your project and you should not have any more this error

If you do have then one solution is to delete the content of the obj folder in the project generated by compiler.


I added to my website publish script. At the end, delete the obj folder from your website folder.


If you face this problem while publishing your website or application on some server, the simple solution I used is to convert folder which contains files to web application.


In our case, we were deploying a site out to a server which was replicated across other servers. Performing an IISRESET on all servers in the deployment environment worked.


Via Visual Studio, I had published a WCF Service via FTP, to an external server. It worked fine locally, and when publishing to an internal server, but not to the external. The solution was to publish without providing a Site Path (in other words, publish directly to the root of the virtual directory).

I'm not sure why it worked, since I had already tried moving the files to the root via an external FTP Client - among many other attempts, including all listed here. Maybe it was something with the publish profile, like it was for FabianVal. But I'm not in the mood of testing anymore at this point, since I'm in a hurry to get up to speed after all the days wasted on this problem.


After deleting Crystal Reports Backup Files from the project folder it is working for me.


In Visual Studio 2013 I struggled with this for a while and it is pretty much easy to solve just follow what the exceptions says "virtual directory not being configured as an application in IIS"

In my case I had WebService planted inside IIS website so

  1. I opened the website in IIS manager
  2. right clicked the WCF folder
  3. clicked Convert to Application
  4. and then submitted with Ok

WCF is back and running.


I've this problem more frequent if "true" is enabled in the project file.

  1. Set false

As Jonny says:

  1. Clean solution whilst your solution is configured in Release mode.
  2. Clean solution whilst your solution is configured in Debug mode.
  3. Build whilst your solution is configured in Debug mode.

tip 1: clean & then rebuild.

tip 2: just close VS and open again.

tip 3: the downloaded project may be inside another sub folder... open the folder which has you .net files.

c:/demo1/demo/ (all files)

You should have to open demo from vs... not demo1.


I had the same problem because a new global Web.Config is automatically created for the parent folder. It was \Website\Website.

After I moved all file from the child folder to the parent and delete the child folder, now I have only one Web.Config and the problem is resolved.


If you have MVC project with enabled views build, one of the solution is to delete obj folder before build. Add to project file:

<Target Name="BeforeBuild">
    <!-- Remove obj folder -->
    <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
    <!-- Remove bin folder -->
    <RemoveDir Directories="$(BaseOutputPath)" />
</Target>

Here is article: How to remove bin and/or obj folder before the build or deploy


A recent web.config change may be in the wrong web.config file.

A <machineKey...> property had been added to Views/web.config. No matter how many Cleans and Rebuilds the error remained. The fix was to move the property into the root /web.config.


It may be the version problem like you download the project of .Net framework 2.0 and want to open it into the VS2008 then you will need to upgrade to the latest version and VS will create the Backup of the folder in same root directory.You will get the answer here.


I've got the same problem in VS 2013 after publishing my project in debug mode. The problem has been solved by removing obj/ files