4

I have not been able to start my ASP.NET Core 3.1 in IIS (v10) the way I would expect. I publish to site to folders like normal, but when I test from within my Windows Server 2019 VM by going to http://localhost:80 or https://localhost:443 (to both of which the IIS site is bound), I just get a 500.19 response. BUT if from the command line, I enter dotnet MyWebApp.dll, then the site DOES appear at https://localhost:5001/.

What's going on? Why isn't port 80 working automatically, given that it's bound there in IIS?

Is there some trick to make this work just by copying the files over and using IIS, or am I REQUIRED to use the command line to start a .NET Core 3.1 site?

David
  • 2,782
  • 4
  • 31
  • 47

2 Answers2

8

Make sure you've done the following:

  • Installed latest Core hosting bundle. If not, go here and look for "Hosting Bundle" https://dotnet.microsoft.com/download/dotnet-core/3.1 (you should go there on regular basis, a new version about every month, latest is 3.1.7 when writing this)
  • In app pool, make sure .NET framework is not selected

When publish, use

Deployment Mode = Framework-Dependent
Target Runtime = win-x64

In your publish profile (you find this file in project folder /Properties/PublishProfiles/YourProfileName.pubxml) after saving the profile, you'll need

<EnvironmentName>Production</EnvironmentName>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

InProcess is the fastest option when using IIS. When running publish, this will end up in your generated web.config like this

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath=".\YourWebApp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>
</configuration>

When deploying to a staging server, create a new publish profile, and use

<EnvironmentName>Staging</EnvironmentName>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

When you get answer from https://localhost:5001/ you are running Kestrel, not IIS

Roar S.
  • 8,103
  • 1
  • 15
  • 37
  • I had the windows runtime (even the SDK), but not the "hosting bundle". I didn't notice it right below the runtime, nor did I even think to look for it! Thank you very much. – David Aug 19 '20 at 05:04
  • Good too hear that things are working now. Installing hosting bundle fixes IIS support, that is the main difference. – Roar S. Aug 19 '20 at 08:11
0

It seems that you missed to install Asp.net Core web hosting bundle. Asp.net core is not supported by IIS by default even you can run it in Visual studio IIS express. Besides, IIS won't register AspNetCore handler even when you install asp.net core web hosting bundle.

So please ensure you have registered the handler and asp.net core module in web.config

<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\MyWebApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>

Of course, you can publish your application with VS web deployment tool. It will register these configuration when you publish the project.

https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1

Jokies Ding
  • 3,374
  • 1
  • 5
  • 10