Deepali
Deepali

Reputation: 2029

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?

Upvotes: 197

Views: 361560

Answers (30)

Mantra
Mantra

Reputation: 346

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>

Upvotes: 0

Shrikant Dandile
Shrikant Dandile

Reputation: 404

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.

Upvotes: 0

Moumit
Moumit

Reputation: 9510

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

Upvotes: 0

Eduardo Molteni
Eduardo Molteni

Reputation: 39413

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)

Upvotes: 83

Aske B.
Aske B.

Reputation: 6609

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.

Upvotes: 1

Auguste
Auguste

Reputation: 2189

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.

Upvotes: 0

user1477388
user1477388

Reputation: 21420

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.

Upvotes: 0

Druid
Druid

Reputation: 6453

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.

Upvotes: 5

pepr
pepr

Reputation: 20744

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.

Upvotes: 5

Md. Ilyas Hasan Mamun
Md. Ilyas Hasan Mamun

Reputation: 1888

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

Upvotes: 0

Marek
Marek

Reputation: 3575

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.

Upvotes: 13

FabianVal
FabianVal

Reputation: 373

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!

Upvotes: 0

SushiGuy
SushiGuy

Reputation: 1627

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.

Upvotes: 8

Ricky Gummadi
Ricky Gummadi

Reputation: 5222

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

Upvotes: 1

Daniel Silva
Daniel Silva

Reputation: 837

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.

Upvotes: 1

Grigory Bushuev
Grigory Bushuev

Reputation: 883

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

Upvotes: 1

Gautam Beri
Gautam Beri

Reputation: 157

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.

Upvotes: 2

Igor
Igor

Reputation: 3656

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

Upvotes: 13

rovsen
rovsen

Reputation: 5022

Delete bin and obj folders. Then rebuild the solution.

Upvotes: 2

GPGVM
GPGVM

Reputation: 5619

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.

Upvotes: 0

Gaff
Gaff

Reputation: 5657

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.

Upvotes: 0

gaijintendo
gaijintendo

Reputation: 423

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.

Upvotes: 3

ehabh86
ehabh86

Reputation: 31

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.

Upvotes: 1

visar_uruqi
visar_uruqi

Reputation: 2494

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.

Upvotes: 6

NicoJuicy
NicoJuicy

Reputation: 3528

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

Upvotes: 4

Praveen Tiwari
Praveen Tiwari

Reputation: 1310

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.

Upvotes: 4

Rob Sedgwick
Rob Sedgwick

Reputation: 4514

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.

Upvotes: 1

Pete
Pete

Reputation: 161

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

Upvotes: 16

Ilya
Ilya

Reputation: 71

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

Upvotes: 2

gofor.net
gofor.net

Reputation: 4298

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.

Upvotes: 2

Related Questions