28
votes

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:\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.

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

Unable to start process C:\Program Files\dotnet\dotnet.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}\AppData\Local\Temp\HttpFailure_08-05-50.html.

The HTML file contains this information:

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

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:

screenshot of add remove programs with hosting component installed

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

Screenshot of modules list in IIS

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:\Code\Sandbox\IisTestApp\IisTestApp\web.config
Error:

Screenshot of site modules 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 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]

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="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 .\ 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:\Code\Sandbox\IisTestApp\IisTestApp
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=".\logs\stdout">
  <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.

6

6 Answers

34
votes

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%\system32\inetsrv\config. 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.

13
votes

Installing the .NET Core Hosting Bundle resolved the problem for me. Here is a link to the .NET Core Hosting Bundle.

Using .NET Core 3.1

5
votes

I tried using the above suggestion, but didn't work. So, I reinstalled the Asp Net Core Runtime Hosting in Administrator Mode, and my ApplicationHost.Config got corrected.

3
votes

If you install the .NET Core Windows Hosting Bundle, but the AspNetCoreModule still doesn't appear on your applicationHost.config, you can try to do what I did to solve my problem, after trying all the other solutions on SO and other places.

I found an applicationHost.config in another server that had those AspNetCoreModule lines and updated the file on the broken server. Not sure why they were not being added by the .NET Core installation.

I added the line below under the <globalModules> section:

<add name="AspNetCoreModule" image="%SystemRoot%\system32\inetsrv\aspnetcore.dll" />

And this one under <modules>:

<add name="AspNetCoreModule" />

Hope this helps.

3
votes

Installing the .NET Core Hosting Bundle resolved the problem (like in answer upper)

In my case solution was simple, just restore Hosting bundle, and it helped. Before restore I get hresult 0x8007000d. In iis for net core applications, modules were not loaded.

some image for more info

0
votes

I also get this error on dotnet core 3.1.

After removing wrapper section from web.config application starts work:

enter image description here

Changed to:

<?xml version="1.0" encoding="UTF-8"?>
  <configuration>
     <system.webServer>
       <handlers>
          <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
       </handlers>
       <aspNetCore processPath="dotnet" arguments=".\ContactForm.Microservice.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
     </system.webServer>
  </configuration>