错误:allowDefinition=“MachineToApplication”超越应用层

发布于 2024-08-23 12:13:17 字数 215 浏览 3 评论 0原文

我已经下载了 ASP.Net 的在线项目。运行应用程序时出现错误

在应用程序级别之外使用注册为allowDefinition='MachineToApplication' 的节是错误的。此错误可能是由于未将虚拟目录配置为 IIS 中的应用程序而导致的。

我应该在 web.config 或其他地方进行哪些更改才能使其正常工作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

帥小哥 2024-08-30 12:13:17

我刚刚遇到了这种“喜悦”。它似乎在我以发布模式发布 Web 应用程序后就出现了。

持续解决我发现的问题的唯一方法是遵循此清单:

  1. 在发布模式下配置解决方案时清理解决方案。
  2. 当您的解决方案配置为调试模式时,清理解决方案。
  3. 在您的解决方案配置为调试模式时进行构建。

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.
黑色毁心梦 2024-08-30 12:13:17

刚刚看到这篇文章,这就发生在我身上。
只需清理项目,错误就会消失。 (一定是VS2010的bug)

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)

凯凯我们等你回来 2024-08-30 12:13:17

我在构建网站的第二个版本时刚刚遇到了这个问题。当我第一次构建它时并没有发生这种情况。

我刚刚删除了 bin 和 obj 文件夹,运行 Clean 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.

孤者何惧 2024-08-30 12:13:17

没有任何。您需要将放置网站的目录设置为 IIS 中的 Web 应用程序

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

走过海棠暮 2024-08-30 12:13:17

当您尝试将项目作为网站打开时,会出现此错误。确定您是否已创建网站或项目的最简单方法是检查您的解决方案文件夹(即保存代码的位置)并查看根目录中是否有 *.sln 文件,如果有,那么您'创建了一个项目。

只是补充一下,当我尝试打开不久前通过从 Visual Studio 菜单中选择“文件”、“打开网站”创建的项目时,我遇到了此错误,而我应该选择“文件”、“打开项目”反而。我一意识到就捂脸:)

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

天赋异禀 2024-08-30 12:13:17

如果您的 MVC 项目启用了视图构建,解决方案之一是在构建之前删除 obj 文件夹。添加到项目文件:

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

这是文章:如何删除 bin 和/或构建或部署之前的 obj 文件夹

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

不必你懂 2024-08-30 12:13:17

在 Visual Studio 2013 中,我为此苦苦挣扎了一段时间,而且很容易解决只需遵循异常情况 “虚拟目录未配置为 IIS 中的应用程序”

就我而言,我已将 WebService 植入 IIS 网站 中,因此

  1. 我在 IIS 管理器中打开该网站,
  2. 右键单击 WCF 文件夹,
  3. 然后单击转换为应用程序
  4. 并然后使用 Ok 提交

WCF 已恢复并运行。

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.

倒带 2024-08-30 12:13:17

该错误表明您正在使用的代码期望在 IIS 上设置虚拟目录。

查找文档并添加所需的虚拟目录。它应该是一个包含 web.config 的目录(而不是根目录)。

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

浅笑轻吟梦一曲 2024-08-30 12:13:17

最近的 web.config 更改可能位于错误的 web.config 文件中。

属性已添加到 Views/web.config 中。无论清理和重建多少次,错误仍然存​​在。修复方法是将属性移至根目录 /web.config 中。

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.

眼泪都笑了 2024-08-30 12:13:17

如果您遇到此错误

使用注册为的部分是错误的
allowDefinition='MachineToApplication' 超出应用程序级别。这
错误可能是由于虚拟目录未配置为
IIS 中的应用

解决方案
我在 VS 2012 中也遇到了同样的问题。
我通过

  1. 卸载当前项目
  2. 解决了这个问题编辑您的.csproj
  3. 找到这个false
  4. 而不是false将值更改为true
  5. 再次加载您的项目,您应该不会再出现此错误。

如果确实有,那么一种解决方案是删除编译器生成的项目中 obj 文件夹的内容。

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.

柠檬心 2024-08-30 12:13:17

就我而言,问题仅在我将项目发布到子目录后才出现。由于我缺乏知识,我将 web_publish 子目录放置在 web_project 目录中。

很明显,web_publish 还包含与项目相同的 Web.config。但是,web_project 不知道在嵌套子目录中搜索 Web.config 时应避免我的 web_publish。这样,Web.config 就被重复了,并且出现了错误。

解决方案是将我的 web_publish 放在其他地方。

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.

似狗非友 2024-08-30 12:13:17

就我而言,有一个“备份”文件夹,其中包含整个网站的另一个副本。这意味着另一个web.config,因此构建失败并出现此错误。我删除了“备份”文件夹,在调试和发布版本上执行了干净的解决方案,错误消失了。

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.

枫林﹌晚霞¤ 2024-08-30 12:13:17

就我而言,

解决方案包含 6 个项目、1 个主目录和 5 个子目录。所有子目录都有 web.config。

当运行子目录中的任何页面时,我遇到了同样的错误。

我从 web.config 中删除了这一行,

<authentication mode="Windows"/>

这对我有用。

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.

愿与i 2024-08-30 12:13:17

清理你的项目
删除 /obj 文件夹(可能使用发布和部署? - 其中有一个错误)

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

如梦亦如幻 2024-08-30 12:13:17

我的问题是我不小心将我的 Web 服务发布到了全新安装的 VS2010 上预先完成的位置。

我已经发布到一个名为 PreCompiledWeb 的文件夹,并且我怀疑 web.config 的存在搞砸了。

我只是简单地删除了文件夹,然后刷新了项目。

当双击这个错误时 - 它把我带到了那个错误的 web.config 文件,这给了我提示。

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.

浅沫记忆 2024-08-30 12:13:17

可能是版本问题,比如你下载了.Net Framework 2.0的项目,想在VS2008中打开它,那么你需要升级到最新版本,VS会在同一根目录下创建文件夹的备份。你会此处获取答案。

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.

茶花眉 2024-08-30 12:13:17

在使用在我的解决方案中创建的 Web 部署项目构建解决方案时,我遇到了此错误。我通过删除构建 Web 部署项目的文件夹来解决该错误。此文件夹在 WDP 属性的“项目文件夹”属性中指定

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

來不及說愛妳 2024-08-30 12:13:17

删除 bin 和 obj 文件夹。然后重建解决方案。

Delete bin and obj folders. Then rebuild the solution.

心头的小情儿 2024-08-30 12:13:17

显然我的解决方案中有两个 web.config 文件。我正在使用 MVC4,视图下有另一个配置文件,我在错误的文件中进行了更改。固定在那里帮助了我。

但您始终可以更改 global.asax 文件中的默认重定向/路由。

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.

用心笑 2024-08-30 12:13:17

可能您的项目文件夹中有一个子 asp.net 项目文件夹,该文件夹未配置为虚拟目录。设置项目以在 IIS 中运行。

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.

天涯沦落人 2024-08-30 12:13:17

我添加到我的网站发布脚本。最后,从网站文件夹中删除 obj 文件夹。

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

深海里的那抹蓝 2024-08-30 12:13:17

如果在项目文件中启用“true”,我会更频繁地遇到此问题。

  1. 设置 false

正如 Jonny 所说:

  1. 在您的解决方案配置为发布模式时清理解决方案。
  2. 当您的解决方案配置为调试模式时,清理解决方案。
  3. 在您的解决方案配置为调试模式时进行构建。

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.
梦忆晨望 2024-08-30 12:13:17

我有一个项目,我不想成为一个网络应用程序,我希望它成为一个文件夹。答案是完全删除 web.config 文件。它只属于应用程序的根目录。

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.

蹲在坟头点根烟 2024-08-30 12:13:17

如果您在某些服务器上发布网站或应用程序时遇到此问题,我使用的简单解决方案是将包含文件的文件夹转换为 Web 应用程序。

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.

影子的影子 2024-08-30 12:13:17

在调试模式下发布我的项目后,我在 VS 2013 中遇到了同样的问题。通过删除 obj/ 文件已解决该问题

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

烂柯人 2024-08-30 12:13:17

我有一个网站项目。

就我而言,我已将解决方案文件移动到另一个路径,这导致了问题。我将其恢复到之前的位置,问题就解决了。

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.

一梦等七年七年为一梦 2024-08-30 12:13:17

对于任何仍在寻找的人,我的解决方案是删除 bin 和 obj 文件夹并重新启动 Visual Studio 似乎可以修复它。

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

兲鉂ぱ嘚淚 2024-08-30 12:13:17

通过 Visual Studio,我通过 FTP 发布了 WCF 服务到外部服务器。它在本地运行良好,并且在发布到内部服务器时运行良好,但发布到外部服务器时则不然。解决方案是发布而不提供站点路径(换句话说,直接发布到虚拟目录的根目录)。

我不知道为什么它会起作用,因为我已经尝试通过外部 FTP 客户端将文件移动到根目录 - 还有许多其他尝试,包括此处列出的所有尝试。也许是发布配置文件的问题,就像 FabianVal 的内容一样。但我现在没有心情再进行测试,因为在这个问题上浪费了很多时间之后,我急于加快速度。

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.

那小子欠揍 2024-08-30 12:13:17

秘诀1:清洁与清洁然后重建。

提示2:关闭VS并再次打开即可。

提示 3:下载的项目可能位于另一个子文件夹中...打开包含 .net 文件的文件夹。

c:/demo1/演示/
(所有文件)

您应该从 vs...而不是 demo1 打开演示。

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.

音盲 2024-08-30 12:13:17

我尝试了上面的每个解决方案,但没有一个能够解决我的问题。 (我确信这个问题有 1000 个解决方案)对于我的场景,我试图将测试中的 WCF Web 服务发布到生产环境中。

然而,我没有意识到在生产中我们仅使用 HTTPS,这意味着我们将所有内容重定向到 HTTPS。事实证明,我是通过 HTTP 而不是 HTTPS 指向服务,从而导致了错误。此场景的解决方案是将地址协议更改为 HTTPS 而不是 HTTP。

我希望这能帮助那些试图解决这个问题的可怜人。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文