@manhng

Welcome to my blog!

Publishing and Running ASP.NET Core Applications with IIS (AspNetCoreModule)

November 6, 2019 16:47

Publishing and Running ASP.NET Core Applications with IIS (edit)

Install .NET Core, ASP.NET Core

https://www.tutorialsteacher.com/core/aspnet-core-environment-setup

Install DotNetCore.1.0.0-WindowsHosting.exe

https://go.microsoft.com/fwlink/?LinkId=817246 (DotNetCore.1.0.0-WindowsHosting.exe)

https://github.com/dotnet/core/tree/master/release-notes

DotNetCore 1.0.10

https://github.com/dotnet/core/blob/master/release-notes/download-archives/1.0.10-download.md

The ASP.NET Core Hosting Bundle includes the .NET Core runtime and ASP.NET Core runtime.

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-3.1&viewFallbackFrom=aspnetcore-1.0

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-3.1&viewFallbackFrom=aspnetcore-1.1

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-3.1&viewFallbackFrom=aspnetcore-2.0

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.1

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.2

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-3.0

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

How to detect .NET Core installed versions?

.NET Framework

https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed

.NET Core

dotnet --info

dotnet --version

https://docs.microsoft.com/en-us/dotnet/core/install/how-to-detect-installed-versions?pivots=os-windows

  • dotnet executable
    C:\program files\dotnet\dotnet.exe

  • .NET SDK
    C:\program files\dotnet\sdk\{version}\

  • .NET Runtime
    C:\program files\dotnet\shared\{runtime-type}\{version}\

How to determine if .NET Core is installed using PowerShell

https://stackoverflow.com/questions/38567353/how-to-determine-if-net-core-is-installed

(dir (Get-Command dotnet).Path.Replace('dotnet.exe', 'shared\Microsoft.NETCore.App')).Name
(dir (Get-Command dotnet).Path.Replace('dotnet.exe', 'sdk')).Name

ASP.NET Core Applications in IIS

https://weblog.west-wind.com/posts/2018/Jun/05/Which-NET-Core-Runtime-Download-do-you-need

https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications-with-IIS

Hosting ASP.NET on IIS

ASP.NET Core Applications with IIS

ASP.NET Core IIS Hosting

As of ASP.NET Core 2.2 IIS Hosting does support a new InProcess hosting mechanism. A seperate post describes the details of In Process/Out of Process hosting.

The AspNetCoreModule has to be installed on your server and is part of the ASP.NET Core Server Hosting Bundle.

The ASPNetCoreModule interfaces ASP.NET Core Console Applications

Here's what the web.config looks like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!--
    Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
  -->
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*"
        modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet"
                arguments=".\AlbumViewerNetCore.dll" 
                stdoutLogEnabled="false" 
                stdoutLogFile=".\logs\stdout" 
                forwardWindowsAuthToken="false" />
  </system.webServer>
</configuration>

You can see that module references dotnetexe and the compiled entry point DLL that holds your Main method in your .NET Core application.

You can also provide an optional section for Environment Variables if you were explicitly configuring various configuration startup environment settings.

Web.config

<aspNetCore processPath="dotnet"
                arguments=".\AlbumViewerNetCore.dll" 
                stdoutLogEnabled="false" 
                stdoutLogFile=".\logs\stdout" 
                forwardWindowsAuthToken="false">
    <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
        
    </environmentVariables>
</aspNetCore>    

Note that you should use these settings sparingly and rather rely on the configuration settings object which gives you more control. Limit environment variable settings for specific startup options you need to configure the global environment. Otherwise stick to configuration file settings - or on Azure use the application settings to merge values into your config.

IIS Identity and Permissions

You might also have to tweak the IIS App Pool Identity to something other than the default ApplicationPoolIdentity in order to ensure that your application has access to resources it needs to run. I generally start with NETWORKSERVICE and then move to a custom account that matches the actual rights required by the application.

Code Samples for book "Learning Windows Server Containers"

https://github.com/vishwanathsrikanth/learningwsc

https://github.com/vishwanathsrikanth/mycode/tree/master/aspnetcore-iis/musicstore/

Categories

Recent posts