15 KiB
title | author | description | ms.author | ms.custom | ms.date | uid |
---|---|---|---|---|---|---|
Deploy ASP.NET Core apps to Azure App Service | guardrex | This article contains links to Azure host and deploy resources. | riande | mvc | 10/24/2018 | host-and-deploy/azure-apps/index |
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
The Azure Web Apps 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:
Quickstart: 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.
Quickstart: Create a .NET Core web 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:
xref:tutorials/publish-to-azure-webapp-using-vs
Learn how to publish an ASP.NET Core app to Azure App Service using Visual Studio.
xref:host-and-deploy/azure-apps/azure-continuous-deployment
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 with Azure Pipelines
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.
::: moniker range=">= aspnetcore-2.0"
Application configuration
The following NuGet packages provide automatic logging features for apps deployed to Azure App Service:
- Microsoft.AspNetCore.AzureAppServices.HostingStartup uses IHostingStartup to provide ASP.NET Core light-up integration with Azure App Service. The added logging features are provided by the
Microsoft.AspNetCore.AzureAppServicesIntegration
package. - Microsoft.AspNetCore.AzureAppServicesIntegration executes AddAzureWebAppDiagnostics to add Azure App Service diagnostics logging providers in the
Microsoft.Extensions.Logging.AzureAppServices
package. - Microsoft.Extensions.Logging.AzureAppServices provides logger implementations to support Azure App Service diagnostics logs and log streaming features.
If targeting .NET Core and referencing the Microsoft.AspNetCore.All metapackage, the preceding packages are included. The packages are absent from the Microsoft.AspNetCore.App metapackage. If targeting .NET Framework or referencing the Microsoft.AspNetCore.App
metapackage, reference the individual logging packages.
::: moniker-end
Override app configuration using the Azure Portal
The App Settings area of the Application settings blade permits 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 Web Host and builds the host using WebHost.CreateDefaultBuilder, environment variables that configure the host use the ASPNETCORE_
prefix. For more information, see xref:fundamentals/host/web-host and the Environment Variables Configuration Provider.
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 xref:fundamentals/host/generic-host and the Environment Variables Configuration Provider.
Proxy server and load balancer scenarios
The IIS Integration Middleware, which configures Forwarded Headers Middleware, 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
For monitoring, logging, and troubleshooting information, see the following articles:
How to: Monitor Apps in Azure App Service
Learn how to review quotas and metrics for apps and App Service plans.
Enable diagnostics logging for web apps in Azure App Service
Discover how to enable and access diagnostic logging for HTTP status codes, failed requests, and web server activity.
xref:fundamentals/error-handling
Understand common approaches to handling errors in ASP.NET Core apps.
xref:host-and-deploy/azure-apps/troubleshoot
Learn how to diagnose issues with Azure App Service deployments with ASP.NET Core apps.
xref:host-and-deploy/azure-iis-errors-reference
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 xref:security/data-protection/implementation/key-storage-providers.
Deploy ASP.NET Core preview release to Azure App Service
Use one of the following approaches:
- Install the preview site extension.
- Deploy the app self-contained.
- Use Docker with Web Apps for containers.
Install the preview site extension
If a problem occurs using the preview site extension, open an issue on GitHub.
- From the Azure Portal, navigate to the App Service blade.
- Select the web app.
- Type "ex" in the search box or scroll down the list of management sections to DEVELOPMENT TOOLS.
- Select DEVELOPMENT TOOLS > Extensions.
- Select Add.
- Select the ASP.NET Core <x.y> (x86) Runtime extension from the list, where
<x.y>
is the ASP.NET Core preview version (for example, ASP.NET Core 2.2 (x86) Runtime). The x86 runtime is appropriate for framework-dependent deployments that rely on out-of-process hosting by the ASP.NET Core Module. - Select OK to accept the legal terms.
- Select OK to install the extension.
When the operation completes, the latest .NET Core preview is installed. Verify the installation:
-
Select Advanced Tools under DEVELOPMENT TOOLS.
-
Select Go on the Advanced Tools blade.
-
Select the Debug console > PowerShell menu item.
-
At the PowerShell prompt, execute the following command. Substitute the ASP.NET Core runtime version for
<x.y>
in the command:Test-Path D:\home\SiteExtensions\AspNetCoreRuntime.<x.y>.x86\
If the installed preview runtime is for ASP.NET Core 2.2, the command is:
Test-Path D:\home\SiteExtensions\AspNetCoreRuntime.2.2.x86\
The command returns
True
when the x64 preview runtime is installed.
::: moniker range=">= aspnetcore-2.2"
[!NOTE] The platform architecture (x86/x64) of an App Services app is set in the Application Settings blade under General Settings 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 (for example, ASP.NET Core 2.2 (x64) Runtime).
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\
If the installed preview runtime is for ASP.NET Core 2.2, the command is:
Test-Path D:\home\SiteExtensions\AspNetCoreRuntime.2.2.x64\
The command returns
True
when the x64 preview runtime is installed.
::: moniker-end
[!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:
Deploy the app self-contained
A self-contained deployment (SCD) that targets a preview runtime carries the preview runtime in the deployment.
When deploying a self-contained app:
- The site in Azure App Service doesn't require the preview site extension.
- The app must be published following a different approach than when publishing for a framework-dependent deployment (FDD).
Publish from Visual Studio
- Select Build > Publish {Application Name} from the Visual Studio toolbar.
- In the Pick a publish target dialog, confirm that App Service is selected.
- Select Advanced. The Publish dialog opens.
- 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.
- Create a new site or update an existing site by following the remaining prompts of the publish wizard.
Publish using command-line interface (CLI) tools
-
In the project file, specify one or more Runtime Identifiers (RIDs). Use
<RuntimeIdentifier>
(singular) for a single RID, or use<RuntimeIdentifiers>
(plural) to provide a semicolon-delimited list of RIDs. In the following example, thewin-x86
RID is specified:<PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> <RuntimeIdentifier>win-x86</RuntimeIdentifier> </PropertyGroup>
-
From a command shell, publish the app in Release configuration for the host's runtime with the dotnet publish command. In the following example, the app is published for the
win-x86
RID. The RID supplied to the--runtime
option must be provided in the<RuntimeIdentifier>
(or<RuntimeIdentifiers>
) property in the project file.dotnet publish --configuration Release --runtime win-x86
-
Move the contents of the bin/Release/{TARGET FRAMEWORK}/{RUNTIME IDENTIFIER}/publish directory to the site in App Service.
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.
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 Web Apps.
Additional resources
- Web Apps overview (5-minute overview video)
- Azure App Service: The Best Place to Host your .NET Apps (55-minute overview video)
- Azure Friday: Azure App Service Diagnostic and Troubleshooting Experience (12-minute video)
- Azure App Service diagnostics overview
- xref:host-and-deploy/web-farm
Azure App Service on Windows Server uses Internet Information Services (IIS). The following topics pertain to the underlying IIS technology: