我有一个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相关问答推荐

try 在 .net 中使用 MS Graph 添加新的应用程序角色时出现 ODataError

您如何处理多个环境的多个 web.config 文件?

Firefox 和 Chrome 之间 1 像素的行高差

ASP MVC 授权除少数之外的所有操作

asp.net - 会话 - 多个浏览器选项卡 - 不同的会话?

有没有办法在外部 javascript 文件中使用<%= someObject.ClientID %>?

等待本地主机,永远!

无法加载文件或程序集 'System.Web.Mvc,版本 = 3.0.0.0,Elmah.MVC 问题

从 IIS 7/8 中的静态内容中删除服务器标头

HttpContext.Current.Cache.Insert 和 HttpContext.Current.Cache.Add 有什么区别

以编程方式添加跨度标签,而不是标签控件?

Asp.net Identity 密码哈希

如何在 ASP.NET MVC3 中配置区域

判断邮箱地址是否对 System.Net.Mail.MailAddress 有效

带有文件名的 ASP.net MVC4 WebApi 路由

IIS 10 上的 ASP.NET Core 404 错误

使 Web.config 转换在本地工作

压力测试 ASP.Net 应用程序

ContentResult 与字符串

从物理路径获取相对虚拟路径