static void

ASP.Net Core in IIS

docs.asp.net

Asp.Net Core 2.2 introduced InProcess hosting for IIS (with the module AspNetCoreModuleV2). It is now default and faster than the old OutOfProcess Kestrel model (and the old AspNetCoreModule IIS module). You can set it back with AspNetCoreHostingModel

Install the Asp Core Hosting Bundle on the server (Core runtime + the IIS module)

Publish

The web.config only appears on "Publish" but you can add one to the project and the <aspNetCore> element will be transformed during Publish with your project dll/exe name.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" 
             path="*" verb="*" 
             modules="AspNetCoreModuleV2" 
             resourceType="Unspecified" />
      </handlers>
      <aspNetCore 
        processPath=".\MyWebsite.exe" 
        stdoutLogEnabled="false" 
        stdoutLogFile=".\logs\stdout" 
        hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

This is framework dependent (not self contained)- using dotnet.exe to call the dll:

      <aspNetCore 
        processPath="dotnet" 
        arguments=".\MyWebsite.dll" 

You can set environmental variables for the process within the aspNetCore element

      <aspNetCore
        processPath=".\MyWebsite.exe"
        stdoutLogEnabled="false"
        stdoutLogFile=".\logs\stdout"
        hostingModel="inprocess">
        <environmentVariables>
          <environmentVariable
            name="ASPNETCORE_ENVIRONMENT" value="ACC" />
        </environmentVariables>
        <!-- also handlerSettings @name="debugFile" and "debugLevel" 
        are useful for debugging  -->
      </aspNetCore>

If you get it wrong, you get cryptic errors like HTTP Error 500.30 - ANCM In-Process Start Failure. Check the event log and turn on stdout (perhaps with handlerSettings/debugLevel).

.Net Core 1

Asp.net Core always runs using it's own web server, Kestrel. It can then be self-hosted, or run on Linux, but for most windows servers, you'll probably run it with IIS, as asp.net always has been.

Hence, in Program.cs, you see both .UseKestrel and .UseIISIntegration.

See Strathweb.com for details and potential errors

Installation

public static void Main(string[] args)
{
    var host = new WebHostBuilder(args)
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();
    host.Run();
}

IIS