Minimal web API gives HTTP 500.19 error on IIS

I am trying to get a .NET 8 minimal web api up and running under IIS on Windows 11. Based on a blog post, I created a new app pool with No managed code as the CLR version[1] and assigned it to the Default Web Site. Everything else is default. Then, from Rider, I use publish to folder to publish my web api project to C:\inetpub\wwwroot. When I choose Manage website=>Browse in IIS manager I get an HTTP 500.19 error:
The requested page cannot be accessed because the related configuration data for the page is invalid.

A quick search suggested this was because my web api uses appsettings.json, so I added a web.config file the project, but that made no difference. The web.config in my source is almost empty:
<?xml version="1.0" encoding="utf-8"?>

<configuration>
    <system.web>
        <compilation debug="true"  />
        <httpRuntime  />
    </system.web>
    <appSettings>
    </appSettings>
</configuration>

But after publishing it grows a little and looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation debug="true" />
    <httpRuntime />
  </system.web>
  <appSettings></appSettings>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath=".\Cts.Mobile.WebApi.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
  </system.webServer>
</configuration>

Many hits on another search tell me the solution here is to remove invalid elements from the config file, but how must I know what is valid or not.
Was this page helpful?