.net IIS Express - 500.19 无法读取配置文件 - 因为它正在查看错误的路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33276878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 09:43:31  来源:igfitidea点击:

IIS Express - 500.19 Cannot read configuration file - because it's looking at the wrong path

.netiis-express

提问by Vitani

I recently renamed my root TFS folder from D:\TFS\systemstfsto D:\TFS\sysbecause one of the project's paths was too long for Windows. Now, when I attempt to run a different project (D:\TFS\sys\companydomain.com\Dev\Flowers\wsBusinessLayer) in VS2013 using IIS Express (Project URL http://localhost:59729/Flowers/wsBusinessLayer/) I get the following error message in the browser:

我最近将我的根 TFS 文件夹从 重命名为D:\TFS\systemstfsD:\TFS\sys因为该项目的路径之一对于 Windows 来说太长了。现在,当我尝试使用 IIS Express(项目 URL http://localhost:59729/Flowers/wsBusinessLayer/)在 VS2013 中运行不同的项目(D:\TFS\sys\companydomain.com\Dev\Flowers\wsBusinessLayer)时,我在浏览器中得到以下错误信息:

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.

Module - IIS Web Core
Notification - BeginRequest
Error Code - 0x80070003
Config Error - Cannot read configuration file
Config File - \?\D:\TFS\systemstfs\companydomain.com\Dev\Flowers\web.config
Requested URL - http://localhost:59729/Flowers/wsBusinessLayer/InformationServices.asmx
Physical Path - D:\TFS\sys\companydomain.com\Dev\Flowers\wsBusinessLayer\InformationServices.asmx

HTTP 错误 500.19 - 内部服务器错误
无法访问请求的页面,因为该页面的相关配置数据无效。

模块 - IIS Web 核心
通知 - BeginRequest
错误代码 - 0x80070003
配置错误 - 无法读取配置文件
配置文件 - \?\D:\TFS\ systemtfs\companydomain.com\Dev\Flowers\web.config
请求的 URL - http://本地主机:59729/Flowers/wsBusinessLayer/InformationServices.asmx
物理路径 - D:\TFS\ sys\companydomain.com\Dev\Flowers\wsBusinessLayer\InformationServices.asmx

(emphasis mine, D: is the second HDD on my machine, not a network share)

(强调我的,D:是我机器上的第二块硬盘,不是网络共享)

It's clear to me what the problem is (the config file path is wrong) but I have no idea how to fix it. I have tried:

我很清楚问题是什么(配置文件路径错误),但我不知道如何修复它。我试过了:

  • Enabling "break on CLR exceptions when thrown"
  • Re-getting the solution from TFS
  • Rebooting
  • Switching to use IIS and then back to Express
  • Googling 500.19, 0x80070003, wrong path, cannot read configuration file, and various combinations of those terms
  • 启用“抛出时中断 CLR 异常”
  • 从 TFS 重新获取解决方案
  • 重启
  • 切换到使用 IIS,然后返回到 Express
  • 谷歌搜索 500.19、0x80070003、错误路径、无法读取配置文件以及这些术语的各种组合

But have had no luck. Has anyone come across this before?

但没有运气。有没有人遇到过这个?

采纳答案by Vitani

Turns out I had to edit %USERPROFILE%\Documents\IISExpress\config\applicationhost.configin the following way -

原来我必须%USERPROFILE%\Documents\IISExpress\config\applicationhost.config按以下方式进行编辑-

<configuration>
  <system.applicationHost>
    <sites>
      <site name="wsBusinessLayer">
        <application path="/">
           <virtualDirectory path="/Flowers" physicalPath="D:\TFS\sys\companydomain.com\Dev\Flowers" />

I don't know how this file gets changed "properly", but editing it manually worked fine.

我不知道这个文件是如何“正确”更改的,但手动编辑它工作正常。

回答by Sonic Soul

Here is another possible solution that doesn't involve fishing for the applicationhost.configfile:

这是另一种可能的解决方案,它不涉及文件钓鱼applicationhost.config

  • Right click Web Project > Web > Project Url > (e.g. 'localhost:5459') and then increment the port numberwhich will force a new entry in that file.
  • 右键单击“Web 项目”>“Web”>“项目 URL”>(例如“localhost:5459”),然后增加端口号,这将强制在该文件中创建一个新条目。

In my case I also needed to change authentication mode which can be done via:

在我的情况下,我还需要更改身份验证模式,可以通过以下方式完成:

  • Select Web Project > press F4 > set Windows Authentication as needed (enabled in my case).
  • 选择 Web 项目 > 按 F4 > 根据需要设置 Windows 身份验证(在我的情况下启用)。

回答by Mahesh

In my case, the following changes resolved this error:

就我而言,以下更改解决了此错误:

Open applicationhost.configfile from [SolutionFolder]>.vs[Hidden Folder]and change the value of overrideModeDefaultattribute in windowsAuthenticationsection from Denyto Allow. As shown below.

打开applicationhost.config文件 from[SolutionFolder]>.vs[Hidden Folder]并将部分中的overrideModeDefault属性值windowsAuthenticationDeny更改为Allow。如下所示。

回答by Anders Juul

In my case, the wrong path was recorded in a .vs folder in the zip i received from colleague. Normally, I'd get source through source repository where .vs is not checked in.

就我而言,错误的路径记录在我从同事那里收到的 zip 中的 .vs 文件夹中。通常,我会通过未签入 .vs 的源存储库获取源代码。

Deleting the .vs folder resolved the problem for me.

删除 .vs 文件夹为我解决了这个问题。

回答by Becky Garyfallou

Changing the port number on my MVC project resolved my issue. I went in circles for over an hour looking for an answer. Thank you Sonic Soul.

更改我的 MVC 项目上的端口号解决了我的问题。我转了一个多小时寻找答案。谢谢索尼克灵魂。

It always amazes me when one tiny tweak can fix something horribly broken.

当一个微小的调整可以修复严重损坏的东西时,它总是让我感到惊讶。

I incremented the port number and the error magically resolved.

我增加了端口号,错误神奇地解决了。

Project Properties > Web > Project Url 

Using Visual Studios 2015.

使用 Visual Studio 2015。

回答by Shan

In my case, I received a new machine but when I try run the source (which is copied from old machine) got this error. Removing applicationhost.config file from .vs\config folder under the source code directory fixed the problem.

就我而言,我收到了一台新机器,但是当我尝试运行源代码(从旧机器复制)时出现此错误。从源代码目录下的 .vs\config 文件夹中删除 applicationhost.config 文件修复了问题。

回答by Jeferson

If you are using Local IIS Web Server, rename the custom virtual directory, save and try again. After this, you can put back the original name.

如果您使用的是本地 IIS Web 服务器,请重命名自定义虚拟目录,保存并重试。在此之后,您可以放回原来的名称。

回答by Brendan L

My setup is a .NET 4.6.1 MVC project hosted as an Azure Cloud Service. I got this error when running locally with Visual Studio 2019 and IIS Express. I was able to fix the error. In my case the error was a red herring and was a symptom of another problem. For me, I had to remove my references to System.http.net, System.runtime, and System.Runtime.InteropServices. Then I added the latest version of those those three references back with Nuget.

我的设置是作为 Azure 云服务托管的 .NET 4.6.1 MVC 项目。使用 Visual Studio 2019 和 IIS Express 在本地运行时出现此错误。我能够修复错误。在我的情况下,错误是一个红鲱鱼,是另一个问题的症状。对我来说,我必须删除对 System.http.net、System.runtime 和 System.Runtime.InteropServices 的引用。然后我用 Nuget 添加了这三个引用的最新版本。

The issue was that my code could not find those three packages. It has issues finding the packages every time I switch my git branch, but that's a completely separate error, and one I'm still trying to resolve. The way I figured out what was wrong was I would run the code and look at the "build" and "debug" output in Visual Studio 2019. I saw errors relating to the code not being able to find System.Http.Net, so I fixed that, then saw the errors with the other packages and fixed them. The real issue was that my code was getting exceptions and not running correctly, it just happened to manifest as this 500.19 error.

问题是我的代码找不到这三个包。每次切换我的 git 分支时,它都会出现查找包的问题,​​但这是一个完全独立的错误,我仍在努力解决这个错误。我找出问题的方法是运行代码并查看 Visual Studio 2019 中的“构建”和“调试”输出。我看到与无法找到 System.Http.Net 的代码相关的错误,所以我解决了这个问题,然后看到了其他包的错误并修复了它们。真正的问题是我的代码出现异常并且没有正确运行,它恰好表现为这个 500.19 错误。

Another possibly contributing factor is that I disabled "just my code" earlier in the day. This seemed to cause my code to not break when exceptions were encountered. Once I turned this back on, my code would break when an exception happened, and this also helped me figure out the cause of the problem. To find this option, go into Tools > Options > Debugging > General > "Enable Just My Code".

另一个可能的促成因素是我在当天早些时候禁用了“仅我的代码”。这似乎导致我的代码在遇到异常时不会中断。一旦我重新打开它,我的代码就会在发生异常时中断,这也帮助我找出问题的原因。要找到此选项,请进入“工具”>“选项”>“调试”>“常规”>“仅启用我的代码”。

Original error: enter image description here

原始错误: enter image description here

回答by Supun De Silva

Had the same issue today.

今天有同样的问题。

Change that caused the issue

导致问题的更改

Moving functionality from a separate controller to home controller. I literally moved a view and the functionality behind it from Controller'X'to HomeController

将功能从单独的控制器转移到家庭控制器。我确实将视图及其背后的功能从Controller'X' 移动HomeController

Nature of the issue

问题的性质

  1. Everything works fine when run via IIS express/ Visual Studio
  2. Every thing works fine when deployed locally to IIS.
  3. Hell breaks loose when deployed to the Deployment machine.
  4. Works fine if I deploy to a 'new Site'in Deployment machine's IIS.
  1. 通过 IIS express/Visual Studio 运行时一切正常
  2. 在本地部署到 IIS 时,一切正常。
  3. 当部署到部署机器时,地狱会崩溃。
  4. 如果我部署到部署机器的 IIS 中的“新站点”,则工作正常。

Fix

使固定

  1. delete the Site/application pool instance from IIS.
  2. Recreate them.
  3. Deploy.
  1. 从 IIS 中删除站点/应用程序池实例。
  2. 重新创建它们。
  3. 部署。

回答by LosManos

In my case I replace ..in my path with a normal folder path.

在我的情况下..,我用普通文件夹路径替换我的路径。

TL;DR

TL; 博士

I did the "clever" trick of utilising the relative path of my script file as I did not want to hard code my folder address.

我使用脚本文件的相对路径做了一个“聪明”的技巧,因为我不想硬编码我的文件夹地址。

"C:\Program Files\IIS Express\iisexpress.exe" /path:"%~dp0..\Lagardsdorren\bin\Debug\netcoreapp2.2\publish" /port:44342

I knew, but it took my some time to realise, that ..is non grata in IIS(express) as it makes it possible to path yourself out of your sites home directory. In my case it didn't but I guessIIS(express) just stops anything with ..in it.

我知道,但我花了一些时间才意识到,这..在 IIS(express)中是不受欢迎的,因为它可以让自己离开站点主目录。就我而言,它没有,但我IIS(express) 只是停止其中的任何..内容。

I don't know how to get back to my clever relative path, but that is for another question.

我不知道如何回到我聪明的相对路径,但那是另一个问题。