ASP.Net Core in IIS
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
- Deployment mode may be
- Framework-Dependent (Core runtime installed)
- Self-contained Much larger (but you can Trim Unused Assemblies).
- The application pool Advanced Settings must Enable 32-Bit Applications to False
- dotnet publish creates a cross-platform x.dll and (from Core 3.0) a x.exe for your current platform ("framework-dependent executable").
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.
<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:
processPath="dotnet"
arguments=".\MyWebsite.dll"
You can set environmental variables for the process within the aspNetCore element
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
- On server, you must install ASP.NET Core Module for IIS (the module in the web.config below). It's not part of the standard windows or standard .net install, so add it with the .net Core runtime (or SDK/Visual Studio).
- Old (now installed with runtime): You also need the Visual C++ Redistributable for Visual Studio 2015 (you probably have earlier versions, not 2015).
- Downloads
- Nuget package Microsoft.AspNetCore.Server.IISIntegration is a dependency of microsoft.aspnetcore
- Windows authentication is configured in Properties/launchSettings.json (and then ultimately in web.config)
"iisSettings": { "windowsAuthentication": true, "anonymousAuthentication": false, "iisExpress": { "applicationUrl": "http://localhost:41000/", "sslPort": 0 } }- Older versions: In Startup.Configure add app.UseIISIntegration() to allow windows authentication to be passed through from IIS.
- in rc1 it was UseIISPlatformHandlerUrl()
public static void Main(string[] args)
{
var host = new WebHostBuilder(args)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
IIS
- IIS becomes a reverse proxy, using the IIS native module AspNetCoreModule (min: IIS 7.5- Windows Server 2008 R2/Windows 7)
- AspNetCoreModule is a fork of HttpPlatformHandler, which was created for Azure to run Node, and from WinServer2016 is part of IIS. It just calls an .exe in a child process (in this case, .net Core running the Kestrel webserver).
- AspNetCoreModule is in the package Microsoft.AspNetCore.Server.IISIntegration
- Asp.Net always runs in Kestrel, either behind IIS, or run directly, in a console or windows service, or on Linux.
- There is still a minimal xml web.config, which tells IIS to hand over to the platform handler - but in VS2017+ it only appears on "Publish".
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*"
modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%"
stdoutLogEnabled="false" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>When you publish, the aspnetCore line is changed:
<aspNetCore processPath="dotnet" arguments=".\MyWebProject.dll"
stdoutLogEnabled="false" forwardWindowsAuthToken="false"/>
- IIS no longer handles static files, security, default documents, url rewriting... application pools don't run CLR at all ("No managed code" but can be .net v2 or v4, doesn't matter)
- IIS just does only basic throttling and process management (memory limits, recycling the process etc) AND flowing the auth handles into .net.
- Environmental variables can be set just in the process (not machine wide).
- See announcements 69 and 164
- In RC1, web.config lived in wwwroot only (and publishing was to \artifacts)
- From RC2, web.config lives in the project folder. Publishing is to /bin/Release/PublishOutputs/, with wwwroot as a subfolder.
- From VS2017, web.config disappears, and is only generated in Publish.
- IIS is efficient for static files (and has compression and caching, which Kestrel doesn't). You can change the web.config with StaticFileModule handlers for *.htm*, *.css etc and rewrite rules (as it lives under wwwroot). See here