Asp.Net Core Configuration for IIS deployement

When you build ASP.NET Core applications and plan on running them on IIS, you'll find that .NET Core application in IIS work radically different than previous versions of ASP.NET.

ASP.NET Core with IIS

Things are quite different with ASP.NET Core which doesn't run in-process to the IIS worker process, but rather runs as a separate, out of process Console application that runs its own Web server using the Kestrel component. Kestrel is a .NET Web Server implementation that has been heavily optimized for throughput performance. It's fast and functional in getting network requests into your application, but it's 'just' a raw Web server. It does not include Web management services as a full-featured server like IIS does.

ASP.NET Core applications are standalone Console applications invoked through the dotnet runtime command. They are not loaded into an IIS worker process but rather loaded through a native IIS module called AspNetCoreModule that executes the external Console application.

The AspNetCoreModule is configured via the web.config file found in the application's root, which points a the startup command (dotnet) and argument (your application's main dll) which are used to launch the .NET Core application. The configuration in the web.config file points the module at your application's root folder and the startup DLL that needs to be launched.


Here's what the web.config looks like:

<?xml version="1.0" encoding="utf-8"?>

<configuration>  

  <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. 

<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.

Publishing ASP.NET Core Applications for IIS 

https://www.binkod.in/2020/08/deploy-aspnet-core-application-to-iis.html

Share this:

ABOUT THE AUTHOR

Binkod | A technical blog that helps you with problem-solving solutions. Encourage you to be in touch with the latest technologies. We at BinKod do carry a philosophy that: I'm Impossible.

0 comments

If you have any questions or concerns, please let me know.