可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
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:
- Clean solution whilst your solution is configured in Release mode.
- Clean solution whilst your solution is configured in Debug mode.
- Build whilst your solution is configured in Debug mode.
回答2:
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)
回答3:
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.
回答4:
None. You need to set up the directory you\'ve placed the website as a web application within IIS.
回答5:
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 :)
回答6:
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
- I opened the website in IIS manager
- right clicked the WCF folder
- clicked
Convert to Application
- and then submitted with
Ok
WCF is back and running.
回答7:
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).
回答8:
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
回答9:
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.
回答10:
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
- Unload your current project
- edit your .csproj
- Find this
<MvcBuildViews>false</MvcBuildViews>
- Instead of false change the value to true
- 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.
回答11:
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.config
s that the project contains. However, the web_project
does not know that my web_publish
should be avoided when searching Web.config
s in the nested subdirectories. This way, the Web.config
s were duplicated and the error appeared.
The solution was to place my web_publish
somewhere else.
回答12:
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.
回答13:
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.
回答14:
Clean your project
Remove the /obj folder (probably using publish and deploy? - there is a bug in it)
回答15:
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.
回答16:
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.
回答17:
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
回答18:
Delete bin and obj folders. Then rebuild the solution.
回答19:
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.
回答20:
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.
回答21:
I added to my website publish script. At the end, delete the obj folder from your website folder.
回答22:
I\'ve this problem more frequent if \"true\" is enabled in the project file.
- Set false
As Jonny says:
- Clean solution whilst your solution is configured in Release mode.
- Clean solution whilst your solution is configured in Debug mode.
- Build whilst your solution is configured in Debug mode.
回答23:
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.
回答24:
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.
回答25:
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
回答26:
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.
回答27:
For any one still looking, my solution was to delete both the bin and obj folders and restart visual studio seems to fix it.
回答28:
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.
回答29:
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.
回答30:
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.