我有一个ASP.NET核心应用程序,在IIS Express中运行良好.同样,如果我通过dotnet run从命令行启动应用程序,一切都会顺利进行:

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

如果try 以本地IIS为目标,则会出现以下错误:

无法启动进程C:\Program Files\dotnet\dotnet.exe.web服务器请求失败,状态代码为500,内部服务器错误.完整响应已写入C:\Users{my user name}\AppData\Local\Temp\HttpFailure_08-05-50.html.

HTML文件包含以下信息:

Screenshot of 500.19 error

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:\Code\Sandbox\IisTestApp\IisTestApp\web.config
Requested URL http://localhost:80/IisTestApp
Physical Path C:\Code\Sandbox\IisTestApp\IisTestApp
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

我在网上看到的大多数错误代码都是0x8007000d,这表明我没有正确的答案.NET核心Windows服务器托管组件(AspNetCoreModule),但我肯定已经安装了:

screenshot of add remove programs with hosting component installed

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

Screenshot of modules list in IIS

奇怪的是,如果我try 转到此特定站点的模块页面,得到的错误信息与该网页相同:

执行此操作时出错.

详细信息:

文件名:\?\C:\Code\Sandbox\IisTestApp\IisTestApp\web.配置

Screenshot of site modules error

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

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

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

我的测试应用的目标是:

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

尽管如此,我认为问题确实与IIS和托管组件有关!这里是(默认的)网站.使用项目模板生成的配置:

<?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="bin\IISSupport\VSIISExeLauncher.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 100 relative pathing

如果删除<aspNetCore> node ,则会出现另一个错误:

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:\Code\Sandbox\IisTestApp\IisTestApp
Logon Method Anonymous
Logon User Anonymous

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

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

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

What is causing IIS to fail to run this application?

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

我还注意到,有几篇帖子提到,为IIS安装URL重写模块可以纠正这个错误(尤其是:HTTP Error 500.19 - IIS 7.5 Error 0x8007000d).我的网络.config没有提到那个模块,但我试着安装它,以防AspNetCoreModule在幕后使用它.这对我的处境没有帮助.

推荐答案

排除了我(以及许多有用的 comments 者,尤其是Daboul位 comments 者)可能想到的所有特定于应用程序的内容,并查看了可见的IIS设置,我求助于查看整个IIS的主要配置文件:applicationHost.配置

Introduction to ApplicationHost.config个,这个文件位于%windir%\system32\inetsrv\config.由于真正的应用程序在我办公室的另一台机器上工作,我使用diff程序对它们进行了比较,发现我的配置文件中缺少以下 node :

<?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" />

添加该 node 解决了错误.

奇怪的是,AspNetCoreModule本身在文件中被多次引用.因为我以前没有手动编辑过这个文件,所以在第一次安装AspNetCoreModule时,这可能是某种安装错误.

Asp.net相关问答推荐

如何注册路由区域

在 ASP.Net 中使用自定义 RoleProvider 时如何允许多个角色查看页面

jQuery隐藏字段

如何调试 Azure 500 内部服务器错误

httpCompression 和 urlCompression 有什么区别?

Azure Service Fabric 是否与 Docker 做同样的事情?

返回 HttpResponseMessage 时的 WebAPI Gzip

如何使用 javascript 获取 MVC 应用程序的基本 URL

如何缓存数据库表以防止在 Asp.net C# mvc 中出现许多数据库查询

Jquery asp.net 按钮单击事件通过 ajax

为什么aspx文件会返回404(找不到页面)

如何在 ASP.NET 下拉列表中添加选项组?

是否应该将 project.lock.json 文件签入源代码管理? (ASP.NET 核心 1.0)

单独装配和路由中的控制器

显示 ModalPopupExtender 时如何指定要运行的 javascript

如何通过 Google 图表 API 使用 X 轴中的日期?

HtmlAgilityPack Select 的子 node 不符合预期

会员生成密码 仅限字母数字密码?

Asp.Net web 服务:我想返回错误 403 禁止

您的下一个 ASP.NET 项目的 Select 是什么:Web 窗体还是 MVC?