Deploy ASP.NET Core apps to Azure App Service

Azure App Service is a Microsoft cloud computing platform service for hosting web apps, including ASP.NET Core.

Useful resources

App Service Documentation is the home for Azure Apps documentation, tutorials, samples, how-to guides, and other resources. Two notable tutorials that pertain to hosting ASP.NET Core apps are:

Create an ASP.NET Core web app in Azure
Use Visual Studio to create and deploy an ASP.NET Core web app to Azure App Service on Windows.

Create an ASP.NET Core app in App Service on Linux
Use the command line to create and deploy an ASP.NET Core web app to Azure App Service on Linux.

The following articles are available in ASP.NET Core documentation:

Publish an ASP.NET Core app to Azure with Visual Studio
Learn how to publish an ASP.NET Core app to Azure App Service using Visual Studio.

Continuous deployment to Azure with Visual Studio and Git with ASP.NET Core
Learn how to create an ASP.NET Core web app using Visual Studio and deploy it to Azure App Service using Git for continuous deployment.

Create your first pipeline
Set up a CI build for an ASP.NET Core app, then create a continuous deployment release to Azure App Service.

Azure Web App sandbox
Discover Azure App Service runtime execution limitations enforced by the Azure Apps platform.

Troubleshoot ASP.NET Core projects
Understand and troubleshoot warnings and errors with ASP.NET Core projects.

Application configuration

Platform

Runtimes for 64-bit (x64) and 32-bit (x86) apps are present on Azure App Service. The .NET Core SDK available on App Service is 32-bit, but you can deploy 64-bit apps built locally using the Kudu console or the publish process in Visual Studio. For more information, see the Publish and deploy the app section.

For apps with native dependencies, runtimes for 32-bit (x86) apps are present on Azure App Service. The .NET Core SDK available on App Service is 32-bit.

For more information on .NET Core framework components and distribution methods, such as information on the .NET Core runtime and the .NET Core SDK, see About .NET Core: Composition.

Packages

Include the following NuGet packages to provide automatic logging features for apps deployed to Azure App Service:

The preceding packages aren't available from the Microsoft.AspNetCore.App metapackage. Apps that target .NET Framework or reference the Microsoft.AspNetCore.App metapackage must explicitly reference the individual packages in the app's project file.

Override app configuration using the Azure Portal

App settings in the Azure Portal permit you to set environment variables for the app. Environment variables can be consumed by the Environment Variables Configuration Provider.

When an app setting is created or modified in the Azure Portal and the Save button is selected, the Azure App is restarted. The environment variable is available to the app after the service restarts.

When an app uses the Generic Host, environment variables aren't loaded into an app's configuration by default and the configuration provider must be added by the developer. The developer determines the environment variable prefix when the configuration provider is added. For more information, see .NET Generic Host and the Environment Variables Configuration Provider.

When an app builds the host using WebHost.CreateDefaultBuilder, environment variables that configure the host use the ASPNETCORE_ prefix. For more information, see ASP.NET Core Web Host and the Environment Variables Configuration Provider.

Proxy server and load balancer scenarios

The IIS Integration Middleware, which configures Forwarded Headers Middleware when hosting out-of-process, and the ASP.NET Core Module are configured to forward the scheme (HTTP/HTTPS) and the remote IP address where the request originated. Additional configuration might be required for apps hosted behind additional proxy servers and load balancers. For more information, see Configure ASP.NET Core to work with proxy servers and load balancers.

Monitoring and logging

Azure App Service offers the ASP.NET Core Logging Extensions, which enable logging integration for ASP.NET Core apps. To automatically add the extension to an App Service, use Visual Studio's Publish process with an App Service publish profile. When not using Visual Studio to deploy an app, manually install the extension in the Azure Portal via the App Service's Development Tools > Extensions dialog.

For monitoring, logging, and troubleshooting information, see the following articles:

Monitor apps in Azure App Service
Learn how to review quotas and metrics for apps and App Service plans.

Enable diagnostics logging for apps in Azure App Service
Discover how to enable and access diagnostic logging for HTTP status codes, failed requests, and web server activity.

Handle errors in ASP.NET Core
Understand common approaches to handling errors in ASP.NET Core apps.

Troubleshoot ASP.NET Core on Azure App Service and IIS
Learn how to diagnose issues with Azure App Service deployments with ASP.NET Core apps.

Common errors reference for Azure App Service and IIS with ASP.NET Core
See the common deployment configuration errors for apps hosted by Azure App Service/IIS with troubleshooting advice.

Data Protection key ring and deployment slots

Data Protection keys are persisted to the %HOME%\ASP.NET\DataProtection-Keys folder. This folder is backed by network storage and is synchronized across all machines hosting the app. Keys aren't protected at rest. This folder supplies the key ring to all instances of an app in a single deployment slot. Separate deployment slots, such as Staging and Production, don't share a key ring.

When swapping between deployment slots, any system using data protection won't be able to decrypt stored data using the key ring inside the previous slot. ASP.NET Cookie Middleware uses data protection to protect its cookies. This leads to users being signed out of an app that uses the standard ASP.NET Cookie Middleware. For a slot-independent key ring solution, use an external key ring provider, such as:

  • Azure Blob Storage
  • Azure Key Vault
  • SQL store
  • Redis cache

For more information, see Key storage providers in ASP.NET Core.

Deploy ASP.NET Core preview release to Azure App Service

Use one of the following approaches if the app relies on a preview release of .NET Core:

Install the preview site extension

If a problem occurs using the preview site extension, open an aspnet/AspNetCore issue.

  1. From the Azure Portal, navigate to the App Service.
  2. Select the web app.
  3. Type "ex" in the search box to filter for "Extensions" or scroll down the list of management tools.
  4. Select Extensions.
  5. Select Add.
  6. Select the ASP.NET Core {X.Y} ({x64|x86}) Runtime extension from the list, where {X.Y} is the ASP.NET Core preview version and {x64|x86} specifies the platform.
  7. Select OK to accept the legal terms.
  8. Select OK to install the extension.

When the operation completes, the latest .NET Core preview is installed. Verify the installation:

  1. Select Advanced Tools.

  2. Select Go in Advanced Tools.

  3. Select the Debug console > PowerShell menu item.

  4. At the PowerShell prompt, execute the following command. Substitute the ASP.NET Core runtime version for {X.Y} and the platform for {PLATFORM} in the command:

    Test-Path D:\home\SiteExtensions\AspNetCoreRuntime.{X.Y}.{PLATFORM}\
    

    The command returns True when the x64 preview runtime is installed.

Note

The platform architecture (x86/x64) of an App Services app is set in the app's settings in the Azure Portal for apps that are hosted on an A-series compute or better hosting tier. If the app is run in in-process mode and the platform architecture is configured for 64-bit (x64), the ASP.NET Core Module uses the 64-bit preview runtime, if present. Install the ASP.NET Core {X.Y} (x64) Runtime extension.

After installing the x64 preview runtime, run the following command in the Kudu PowerShell command window to verify the installation. Substitute the ASP.NET Core runtime version for {X.Y} in the command:

Test-Path D:\home\SiteExtensions\AspNetCoreRuntime.{X.Y}.x64\

The command returns True when the x64 preview runtime is installed.

Note

ASP.NET Core Extensions enables additional functionality for ASP.NET Core on Azure App Services, such as enabling Azure logging. The extension is installed automatically when deploying from Visual Studio. If the extension isn't installed, install it for the app.

Use the preview site extension with an ARM template

If an ARM template is used to create and deploy apps, the siteextensions resource type can be used to add the site extension to a web app. For example:

{
    "type": "siteextensions",
    "name": "AspNetCoreRuntime",
    "apiVersion": "2015-04-01",
    "location": "[resourceGroup().location]",
    "properties": {
        "version": "[parameters('aspnetcoreVersion')]"
    },
    "dependsOn": [
        "[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
    ]
}

Deploy a self-contained preview app

A self-contained deployment (SCD) that targets a preview runtime carries the preview runtime in the deployment.

When deploying a self-contained app:

Follow the guidance in the Deploy the app self-contained section.

Use Docker with Web Apps for containers

The Docker Hub contains the latest preview Docker images. The images can be used as a base image. Use the image and deploy to Web Apps for Containers normally.

Publish and deploy the app

Deploy the app framework-dependent

For a 64-bit framework-dependent deployment:

  • Use a 64-bit .NET Core SDK to build a 64-bit app.
  • Set the Platform to 64 Bit in the App Service's Configuration > General settings. The app must use a Basic or higher service plan to enable the choice of platform bitness.
  1. Select Build > Publish {Application Name} from the Visual Studio toolbar or right-click the project in Solution Explorer and select Publish.
  2. In the Pick a publish target dialog, confirm that App Service is selected.
  3. Select Advanced. The Publish dialog opens.
  4. In the Publish dialog:
    • Confirm that the Release configuration is selected.
    • Open the Deployment Mode drop-down list and select Framework-Dependent.
    • Select Portable as the Target Runtime.
    • If you need to remove additional files upon deployment, open File Publish Options and select the check box to remove additional files at the destination.
    • Select Save.
  5. Create a new site or update an existing site by following the remaining prompts of the publish wizard.

Deploy the app self-contained

Use Visual Studio or the command-line interface (CLI) tools for a self-contained deployment (SCD).

  1. Select Build > Publish {Application Name} from the Visual Studio toolbar or right-click the project in Solution Explorer and select Publish.
  2. In the Pick a publish target dialog, confirm that App Service is selected.
  3. Select Advanced. The Publish dialog opens.
  4. In the Publish dialog:
    • Confirm that the Release configuration is selected.
    • Open the Deployment Mode drop-down list and select Self-Contained.
    • Select the target runtime from the Target Runtime drop-down list. The default is win-x86.
    • If you need to remove additional files upon deployment, open File Publish Options and select the check box to remove additional files at the destination.
    • Select Save.
  5. Create a new site or update an existing site by following the remaining prompts of the publish wizard.

Protocol settings (HTTPS)

Secure protocol bindings allow you specify a certificate to use when responding to requests over HTTPS. Binding requires a valid private certificate (.pfx) issued for the specific hostname. For more information, see Tutorial: Bind an existing custom SSL certificate to Azure App Service.

Transform web.config

If you need to transform web.config on publish (for example, set environment variables based on the configuration, profile, or environment), see Transform web.config.

Additional resources

Azure App Service on Windows Server uses Internet Information Services (IIS). The following topics pertain to the underlying IIS technology: