196

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?

Eric J.
  • 147,927
  • 63
  • 340
  • 553
Deepali
  • 2,019
  • 2
  • 13
  • 6
  • 55
    None of the answers found on the web worked for me. My issue was solved by showing all hidden files/folders and deleting the `obj` folder. – The Muffin Man Aug 07 '12 at 17:39
  • 6
    This problem still manifests in VS2012. I have opened a bug report with Microsoft. Anyone experiencing the issue please upvote the bug report https://connect.microsoft.com/VisualStudio/feedback/details/779737/error-allowdefinition-machinetoapplication-beyond-application-level – Eric J. Feb 21 '13 at 20:34
  • 4
    deleting the obj folder resolved this issue for me as well. thanks @Nick! (sorry for the revival) – Jordan Wayne Crabb Jul 31 '13 at 14:43
  • SOLUTION HERE: http://stackoverflow.com/questions/9300927/error-to-use-a-section-registered-as-allowdefinition-machinetoapplication-beyo/9301369#9301369 – benni_mac_b Aug 23 '13 at 23:20
  • in my case, the extra web.config in a sub folder cause this problem. When I remove that extra web.config the error is gone – Dio Phung Jun 11 '14 at 14:39

38 Answers38

97

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.
John Reilly
  • 5,791
  • 5
  • 38
  • 63
  • 18
    Only answer that worked for me also. I had many other errors waiting for me after this but they were unrelated. I got here by setting `MvcBuildViews` to `true`. – Benjamin Apr 01 '13 at 13:42
  • +1 BTW: I think the reason this worked for me was that the most recent build I had was **Debug**. I opened the solution, did a bug fix and attempted to build in R**Release** mode. Cleaning in **Release** didn't work but cleaning in **Debug** did. (Probably a combo of the 2 was what was needed, i.e. clear out **any** old refs to dlls, whether **Debug** or **Release**). – Scotty.NET Jul 19 '13 at 14:34
  • 4
    I did a **clean**, then went to ***project properties -> Web -> Create Virtual Directory** and then the issue was resolved – galdin Nov 28 '13 at 13:16
  • A clean and rebuild while in debug mode are all that is needed for me. No need to switch back and forth between release and debug. But yes, the CLEAN is very important. That's the heart of the matter. – markaaronky Feb 12 '16 at 15:48
  • Why is this not marked as the correct solution? Saved my arse today with a cranky VS2015 project that suddenly decided to go badly sideways. At least it has the highest votes… – René Kåbis Jul 08 '16 at 22:22
  • Maybe this will help those not running a .Net application. I am using Visual Studio for my HTML/JavaScript web application and I do not have access to IIS on my work laptop. So, going to Website -> Start Options -> Build and selecting "No Build" before running start page will keep the error from happening. Since it is not a .Net application, I do not need it to build before running. – Wannabe Nov 04 '16 at 14:09
  • After deploying the web-app on Internet and when I want to go to the admin page (/umbraco), I got same error. Please visit my question: http://stackoverflow.com/q/40923344/1817640 – x19 Dec 02 '16 at 21:40
  • I have an external site where I created a subfolder and put my Web API files/folders which also has a Web.config file. Any idea? – Si8 Mar 22 '17 at 13:25
  • 1
    Clean is not available in my case, which i have never seen before. This is a very old VB.NET application I inherited from a former colleague. – tnk479 Jun 25 '19 at 19:17
82

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)

Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206
25

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.

xiecs
  • 727
  • 11
  • 28
  • 2
    This is the only solution that worked for me in VS Express 2012 for Web. Also, I only started getting this error after I created a solution configuration, and added MvcBuildViews set to true to its PropertyGroup in the .csproj source. – Jeremy Cook Aug 10 '13 at 16:29
20

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

  • 1
    Although technically that's a change "elsewhere to make this work" ;) – Zhaph - Ben Duguid Mar 01 '10 at 14:22
  • 2
    and this is the solution if you get this as an error in your web app! =P – gideon Nov 22 '11 at 04:50
  • I was already setup as an application. Johnny Reilly's solution worked in my case. – Benjamin Apr 01 '13 at 13:40
  • I am just trying to get the template Webforms app to work. It is fine on localhost but not on a server on the LAN. This solution worked for me: VS2015 CE, Windows Server 2008 on my LAN. I used this MS page to explain what to do on IIS: https://support.microsoft.com/en-gb/kb/917413 . No changes to the template code. – Tim Jul 12 '16 at 09:45
16

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 :)

cspolton
  • 4,495
  • 4
  • 26
  • 34
Pete
  • 161
  • 1
  • 2
13

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

Igor
  • 3,576
  • 3
  • 23
  • 18
13

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.

Marek
  • 3,555
  • 17
  • 74
  • 123
  • 1
    I was encountering this issue when I moved my application to Default Website. Point 3 did the trick to resolve my problem. – bikram s. Jul 03 '17 at 09:30
  • This worked for me when we moved to a new web server. After doing a "Convert to Application", the folder symbol changed, and the ASP.NET MVC webapp started working on that web server. – Greg Barth Jun 12 '20 at 16:55
11

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).

Oded
  • 489,969
  • 99
  • 883
  • 1,009
8

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.

SushiGuy
  • 1,573
  • 17
  • 20
  • We had accidentally copied the parent Web.config into the /Views folder. Put the original, much smaller version for the Views folder in there and the site worked again. – Grandizer Oct 03 '16 at 19:05
6

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.

visar_uruqi
  • 2,484
  • 1
  • 23
  • 20
  • 18
    That's weird, setting `MvcBuildViews` to `true` is how I got the error in the first place. – Benjamin Apr 01 '13 at 12:42
  • I also started getting the error message after changing MvcBuildViews to true. I got rid of the error message by changing the value back to false. – Juha Palomäki Jul 17 '13 at 14:08
  • 3
    I did a "Clean solution" in *both* release and debug modes and now the build is working also with `true` – Juha Palomäki Jul 17 '13 at 14:14
  • @JuhaPalomäki super sweet! Thanks. – Haroon Nov 26 '13 at 09:06
  • I had exactly the opposite situation to the @visar_uruqi one. I mean in my **.csproj** file I had the option MvcBuildViews set to true and when I set to false the error was omitted (not shown). – Bronek Dec 28 '13 at 15:05
  • I tell you VS 2013 is a heaven you should upgrade immediately, you won't get any of this annoying errors – visar_uruqi Jan 08 '14 at 09:32
5

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.

pepr
  • 20,112
  • 15
  • 76
  • 139
  • 1
    Well this indeed is the problem of multiple Web.config in your project. Just check your project file and see if the "web.config" is not marked as always copy to output directory. – Mantra Aug 16 '23 at 07:21
5

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.

Druid
  • 6,423
  • 4
  • 41
  • 56
  • I had a similar situation, someone had created a "Published" subfolder within the Website root on the disk (this is an old Web Project, one of the ones with no Solution file), and this had a Web.config in it. The error occurred when Visual Studio tried to build it, and no amount of Cleaning/Deleting "obj" folders etc fixed that, of course. I've seen quite a few instances of this error, and it's almost always a duplicate Web.config hiding away somewhere... (really poor error message as well!) – Detail Oct 14 '16 at 13:20
4

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.

Praveen Tiwari
  • 1,200
  • 1
  • 12
  • 25
  • The line was there but not showing due to some indent problem I guess. I edited and pasted the code in a code block, it shows now. Please check and let me know if I could help in something. – Praveen Tiwari Jan 09 '13 at 09:22
  • Thanks, that confirms the line that it was failing on for me too. I only have one site, so I got around it by opening as a Web Site rather than a project. – Mark Berry Jan 10 '13 at 16:38
4

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

NicoJuicy
  • 3,435
  • 4
  • 40
  • 66
3

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.

gaijintendo
  • 423
  • 2
  • 14
2

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.

gofor.net
  • 4,218
  • 10
  • 43
  • 65
2

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

Ilya
  • 71
  • 5
2

Delete bin and obj folders. Then rebuild the solution.

rovsen
  • 4,932
  • 5
  • 38
  • 60
  • For File Explorer, use search query "obj" kind:=folder and "bin" kind:=folder to find/delete these folders. This worked for me. – Robert J. Good Jun 13 '18 at 15:44
2

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.

Gautam Beri
  • 157
  • 1
  • 6
1

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.
1

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.

Rob Sedgwick
  • 4,342
  • 6
  • 50
  • 87
1

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.

ehabh86
  • 31
  • 3
  • 4
    Hi, welcome to Stack Overflow! Can you please expand your answer? Could you explain how to convert the folder to a Web Application? This'll help others understand your answer better. – Jesse Mar 02 '13 at 13:44
  • 1
    In IIS Manager, under the Connections pane on the right, you right-click the directory under the sites you've created (or Default Web Site), and choose `Convert to Application`. – Aske B. Oct 03 '16 at 06:22
1

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.

funwithcoding
  • 2,412
  • 2
  • 30
  • 41
1

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

Grigory Bushuev
  • 843
  • 9
  • 27
1

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.

Daniel Silva
  • 817
  • 8
  • 16
1

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

Ricky Gummadi
  • 4,559
  • 2
  • 41
  • 67
1

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.

Community
  • 1
  • 1
Aske B.
  • 6,419
  • 8
  • 35
  • 62
1

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

Valamas
  • 24,169
  • 25
  • 107
  • 177
  • you might have some insight: http://stackoverflow.com/questions/6986738/error-allowdefinition-machinetoapplication-beyond-application-level – ekkis Aug 08 '11 at 18:26
0

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.

Learner
  • 346
  • 1
  • 6
  • 16
0

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.

Gaff
  • 5,507
  • 3
  • 38
  • 49
0

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.

GPGVM
  • 5,515
  • 10
  • 56
  • 97
0

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!

FabianVal
  • 374
  • 1
  • 7
0

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

Md. Ilyas Hasan Mamun
  • 1,848
  • 2
  • 24
  • 15
0

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.

user1477388
  • 20,790
  • 32
  • 144
  • 264
0

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.

Auguste
  • 2,007
  • 2
  • 17
  • 25
0

Multiple web.config in same project creates this problem, this could haven created inside/due to Area,views folders.

The solution could be to change the main/root web.config settings to:

Build Action - Content
Copy to Output - Do not Copy

enter image description here

Moumit
  • 8,314
  • 9
  • 55
  • 59
0

In my case, I have Asp.Net Website and I was getting this issue on publish only. The solution that worked for me is id deleted the .vs folder from my code and rebuild the application and then tried to publish and it worked.

Shrikant Dandile
  • 376
  • 3
  • 12
0

You might not always depend upon the luck to clean-up your solution and rebuild it to expect the issue magically disappear. This problem is due to Web.config file getting copied to output directory, here in this case "\bin".

Look for below code in your project file and just comment or remove altogether <CopyToOutputDirectory> from the <content> tag.

<Content Include="Web.config">
    <!-- <CopyToOutputDirectory>Always</CopyToOutputDirectory> -->
</Content>
Mantra
  • 316
  • 3
  • 16