尽管安装了 AspNetCoreModule,但在 IIS 中运行 ASP.NET Core 应用程序时出现错误 500.19 和 0x8007000d [英] Error 500.19 with 0x8007000d when running ASP.NET Core app in IIS despite AspNetCoreModule being installed

查看:28
本文介绍了尽管安装了 AspNetCoreModule,但在 IIS 中运行 ASP.NET Core 应用程序时出现错误 500.19 和 0x8007000d的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 IIS Express 中运行良好的 ASP.NET Core 应用程序.同样,如果我通过 dotnet run 从命令行启动应用程序,则一切正常:

C:CodeSandboxIisTestAppIisTestApp>dotnet run使用 C:CodeSandboxIisTestAppIisTestAppPropertieslaunchSettings.json 中的启动设置...托管环境:生产内容根路径:C:CodeSandboxIisTestAppIisTestApp现在监听:http://localhost:5000现在收听:https://localhost:5001应用程序启动.按 Ctrl+C 关闭.

如果我尝试以本地 IIS 为目标,我会收到以下错误:

<块引用>

无法启动进程 C:Program Filesdotnetdotnet.exe.Web 服务器请求失败,状态代码为 500,内部服务器错误.完整响应已写入 C:Users{我的用户名}AppDataLocalTempHttpFailure_08-05-50.html.

HTML 文件包含以下信息:

<块引用>

HTTP 错误 500.19 - 内部服务器错误

无法访问请求的页面,因为该页面的相关配置数据无效.

详细错误信息:

模块 IIS Web 核心
通知 BeginRequest
处理程序尚未确定
错误代码 0x8007000d
配置错误
配置文件 ?C:CodeSandboxIisTestAppIisTestAppweb.config
请求的 URL

我也可以在IIS的主模块"页面看到它,并验证它指向的文件确实存在:

奇怪的是,如果我尝试转到此特定站点的模块页面,我会收到与网页相同的错误消息:

<块引用>

执行此操作时出错.

详情:

文件名:?C:CodeSandboxIisTestAppIisTestAppweb.config
错误:

此托管模块版本 (2.1.8) 通常与我安装的版本匹配:

C:Users{我的用户名}>dotnet --list-sdks2.1.202 [C:Program Filesdotnetsdk]2.1.504 [C:Program Filesdotnetsdk]C:Users{我的用户名}>dotnet --list-runtimesMicrosoft.AspNetCore.All 2.1.4 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.All]Microsoft.AspNetCore.All 2.1.8 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.All]Microsoft.AspNetCore.App 2.1.4 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]Microsoft.AspNetCore.App 2.1.8 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]Microsoft.NETCore.App 2.0.9 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]Microsoft.NETCore.App 2.1.8 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]

以及我的测试应用的目标:

<属性组><TargetFramework>netcoreapp2.1</TargetFramework></PropertyGroup><项目组><PackageReference Include="Microsoft.AspNetCore.App"/><PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All"/></项目组></项目>

尽管如此,我认为问题确实与 IIS 和该托管组件有关!这是使用项目模板生成的(非常默认的)web.config:

<system.webServer><处理程序><add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/></处理程序><aspNetCore processPath="binIISSupportVSIISExeLauncher.exe" arguments="-argFile IISExeLauncherArgs.txt" stdoutLogEnabled="false"><环境变量/></aspNetCore></system.webServer></位置></配置>

注意:如果我在 processPath 中对完整路径进行硬编码,或者使用 . 相对路径

,我仍然会收到相同的错误消息

如果我删除 <aspNetCore> 节点,我会得到一个不同的错误:

<块引用>

HTTP 错误 502.3 - 错误的网关

尝试路由请求时出现连接错误.

详细错误信息:

模块 AspNetCoreModule
通知 ExecuteRequestHandler
处理程序 aspNetCore
错误代码 0x80070490
请求的 URL http://localhost:80/IisTestApp
物理路径 C:CodeSandboxIisTestAppIisTestApp
登录方法 匿名
登录用户匿名

关键是 AspNetCoreModule 这次抛出了错误,所以 正在加载并运行一些代码.

发布到单独的文件夹并在 IIS 中手动设置站点(而不是依赖于创建指向bin"文件夹的 IIS 网站的默认 Visual Studio 行为)会导致相同的错误消息,尽管我收到了生成的 web.config 文件中的 aspNetCore 节点略有不同:

<aspNetCore processPath="dotnet" arguments=".IisTestApp.dll" stdoutLogEnabled="true" stdoutLogFile=".logsstdout"><环境变量/></aspNetCore>

是什么导致 IIS 无法运行此应用程序?

我尝试重新安装 .NET Core(SDK、运行时和托管组件),但没有帮助.

我还注意到有几篇文章提到为 IIS 安装 URL 重写模块纠正了这个错误(特别是这个:HTTP 错误 500.19 - IIS 7.5 错误 0x8007000d).我的 web.config 没有提到那个模块,但我尝试安装它,以防 AspNetCoreModule 在幕后使用它.这对我的情况没有帮助.

解决方案

排除了我(以及许多有用的评论者,尤其是 Daboul) 可以想到,并且在查看了可见的 IIS 设置后,我求助于查看整个 IIS 的主要配置文件:applicationHost.config

根据 介绍到ApplicationHost.config,这个文件位于%windir%system32inetsrvconfig.由于实际应用程序在我办公室的另一台机器上运行,我使用 diff 程序对它们进行了比较,发现我的配置文件中缺少以下节点:

添加一个节点解决了错误.

奇怪的是,稍后在文件中多次引用了 AspNetCoreModule 本身.由于我之前没有手动编辑过这个文件,这似乎是第一次安装 AspNetCoreModule 时出现的某种安装错误.

I have an ASP.NET Core app that runs great in IIS Express. Similarly, if I launch the app from the command line via dotnet run, everything works smoothly:

C:CodeSandboxIisTestAppIisTestApp>dotnet run
Using launch settings from C:CodeSandboxIisTestAppIisTestAppPropertieslaunchSettings.json...
Hosting environment: Production
Content root path: C:CodeSandboxIisTestAppIisTestApp
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.

If I try to target local IIS, I get the following error:

Unable to start process C:Program Filesdotnetdotnet.exe. The web server request failed with status code 500, Internal Server Error. The full response has been written to C:Users{my user name}AppDataLocalTempHttpFailure_08-05-50.html.

The HTML file contains this information:

HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information:

Module IIS Web Core
Notification BeginRequest
Handler Not yet determined
Error Code 0x8007000d
Config Error
Config File ?C:CodeSandboxIisTestAppIisTestAppweb.config
Requested URL http://localhost:80/IisTestApp
Physical Path C:CodeSandboxIisTestAppIisTestApp
Logon Method Not yet determined
Logon User Not yet determined

Note: in case it's not obvious from that message, this is a minimal repro of my problem, not the actual app

Most of what I see online says that the error code 0x8007000d indicates that I don't have the .NET Core Windows Server Hosting component (AspNetCoreModule), but I definitely have installed that:

I can also see it in the main "Modules" page of IIS, and verified that the file it points to actually exists:

Strangely, if I try to go to the Modules page for this specific site, I get the same error message as the web page:

There was an error while performing this operation.

Details:

Filename: ?C:CodeSandboxIisTestAppIisTestAppweb.config
Error:

This hosting module version (2.1.8) matches generally what I have installed:

C:Users{my user name}>dotnet --list-sdks
2.1.202 [C:Program Filesdotnetsdk]
2.1.504 [C:Program Filesdotnetsdk]

C:Users{my user name}>dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.4 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.8 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.4 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.8 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.9 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.NETCore.App 2.1.8 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]

And what my test app is targeting:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
  </ItemGroup>

</Project>

Despite all that, I think the problem really is related to IIS and that hosting component! Here is the (very default) web.config that is generated with the project template:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="binIISSupportVSIISExeLauncher.exe" arguments="-argFile IISExeLauncherArgs.txt" stdoutLogEnabled="false">
        <environmentVariables />
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

Note: I still get the same error message if I hardcode the full path in the processPath, or use . relative pathing

If I remove the <aspNetCore> node, I get a different error:

HTTP Error 502.3 - Bad Gateway

There was a connection error while trying to route the request.

Detailed Error Information:

Module AspNetCoreModule
Notification ExecuteRequestHandler
Handler aspNetCore
Error Code 0x80070490
Requested URL http://localhost:80/IisTestApp
Physical Path C:CodeSandboxIisTestAppIisTestApp
Logon Method Anonymous
Logon User Anonymous

The point being that the AspNetCoreModule throws the error this time, so it is being loaded and running some code.

Publishing to a separate folder and manually setting up the site in IIS (rather than relying on the default Visual Studio behavior of create an IIS website pointed at the "bin" folder) results in the same error message, although I get a slightly different aspNetCore node in the generated web.config file:

<aspNetCore processPath="dotnet" arguments=".IisTestApp.dll" stdoutLogEnabled="true" stdoutLogFile=".logsstdout">
  <environmentVariables />
</aspNetCore>

What is causing IIS to fail to run this application?

I have tried re-installing .NET Core (SDK, runtime, and hosting component) but it did not help.

I also noticed several posts that mention installing the URL Rewrite module for IIS corrects this error (notably this: HTTP Error 500.19 - IIS 7.5 Error 0x8007000d). My web.config doesn't mention that module, but I tried installing it in case the AspNetCoreModule uses it under the covers. This did not help in my situation.

解决方案

Having ruled out everything app-specific that I (and the many helpful commenters, especially Daboul) could think of, and having reviewed the visible IIS settings, I resorted to looking at the primary configuration file for IIS as a whole: applicationHost.config

Per Introduction to ApplicationHost.config, this file is located in %windir%system32inetsrvconfig. Since the real application is working on a different machine at my office, I compared them using a diff program, and found that the following node was missing from my configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <configSections>
        <!-- ...lots of other stuff... -->
        <sectionGroup name="system.webServer">
            <!-- ...lots of other stuff... -->

            <!--This "section" node for aspNetCore is the one that was missing-->
            <section name="aspNetCore" overrideModeDefault="Allow" />

Adding that one node resolved the error.

Oddly enough, the AspNetCoreModule itself is referenced multiple times later in the file. Since I haven't manually edited this file before, it seems possible that this was some kind of installation error when installing the AspNetCoreModule the first time.

这篇关于尽管安装了 AspNetCoreModule,但在 IIS 中运行 ASP.NET Core 应用程序时出现错误 500.19 和 0x8007000d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆