Deploy ASP.NET Core apps to Azure App Service
Note
This isn't the latest version of this article. For the current release, see the .NET 8 version of this article.
Warning
This version of ASP.NET Core is no longer supported. For more information, see .NET and .NET Core Support Policy. For the current release, see the .NET 8 version of this article.
Important
This information relates to a pre-release product that may be substantially modified before it's commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
For the current release, see the .NET 8 version of this article.
Azure App Service is a Microsoft cloud computing platform service for hosting web apps, including ASP.NET Core.
Reliable web app patterns
See The Reliable Web App Pattern for.NET YouTube videos and article for guidance on creating a modern, reliable, performant, testable, cost-efficient, and scalable ASP.NET Core app, whether from scratch or refactoring an existing app.
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.
See the ASP.NET Core on App Service Dashboard for the version of ASP.NET Core available on Azure App service.
Subscribe to the App Service Announcements repository and monitor the issues. The App Service team regularly posts announcements and scenarios arriving in App Service.
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.
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 and debug ASP.NET Core projects
Understand and troubleshoot warnings and errors with ASP.NET Core projects.
Application configuration
Platform
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 (Basic) or higher hosting tier. Confirm that the app's publish settings (for example, in the Visual Studio publish profile (.pubxml)) match the setting in the app's service configuration in the Azure Portal.
ASP.NET Core apps can be published framework-dependent because the 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:
- Microsoft.AspNetCore.AzureAppServices.HostingStartup uses IHostingStartup to provide ASP.NET Core logging 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.
The preceding packages must be explicitly referenced 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.
Environment variables are loaded into the app's configuration when CreateBuilder is called to build the host. For more information, see the Environment Variables Configuration Provider.
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 Web Host, environment variables are loaded into the app's configuration when CreateDefaultBuilder is called to build the host. 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
ASP.NET Core apps deployed to App Service automatically receive an App Service extension, ASP.NET Core Logging Integration. The extension enables logging integration for ASP.NET Core apps on Azure App Service.
ASP.NET Core apps deployed to App Service automatically receive an App Service extension, ASP.NET Core Logging Extensions. The extension enables logging integration for ASP.NET Core apps on Azure App Service.
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 error troubleshooting 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 an ASP.NET Core app that uses a .NET Core preview
To deploy an app that uses a preview release of .NET Core, see the following resources. These approaches are also used when the runtime is available but the SDK hasn't been installed on Azure App Service.
- Specify the .NET Core SDK Version using Azure Pipelines
- Deploy a self-contained preview app
- Use Docker with Web Apps for containers
- Install the preview site extension
See the ASP.NET Core on App Service Dashboard for the version of ASP.NET Core available on Azure App service.
See Select the .NET Core version to use for information on selecting the version of the .NET SDK for self-contained deployments.
Specify the .NET Core SDK Version using Azure Pipelines
Use Azure App Service CI/CD scenarios to set up a continuous integration build with Azure DevOps. After the Azure DevOps build is created, optionally configure the build to use a specific SDK version.
Specify the .NET Core SDK version
When using the App Service deployment center to create an Azure DevOps build, the default build pipeline includes steps for Restore
, Build
, Test
, and Publish
. To specify the SDK version, select the Add (+) button in the Agent job list to add a new step. Search for .NET Core SDK in the search bar.
Move the step into the first position in the build so that the steps following it use the specified version of the .NET Core SDK. Specify the version of the .NET Core SDK. In this example, the SDK is set to 3.0.100
.
To publish a self-contained deployment (SCD), configure SCD in the Publish
step and provide the Runtime Identifier (RID).
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:
- 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).
Follow the guidance in the Deploy the app self-contained section.
Use Docker with Web Apps for containers
The Docker Hub at https://hub.docker.com/_/microsoft-dotnet
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.
Install the preview site extension
If a problem occurs using the preview site extension, open an dotnet/AspNetCore issue.
- From the Azure Portal, navigate to the App Service.
- Select the web app.
- Type "ex" in the search box to filter for "Extensions" or scroll down the list of management tools.
- Select Extensions.
- Select Add.
- 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. - 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.
Select Go in Advanced Tools.
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}
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 (Basic) or higher hosting tier. Confirm that the app's publish settings (for example, in the Visual Studio publish profile (.pubxml)) match the setting in the app's service configuration in the Azure portal.
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 using the Azure Portal.
After installing the x64 preview runtime, run the following command in the Azure Kudu PowerShell command window to verify the installation. Substitute the ASP.NET Core runtime version for {X.Y}
in the following command:
Test-Path D:\home\SiteExtensions\AspNetCoreRuntime.{X.Y}.x64\
The command returns True
when the x64 preview runtime is installed.
Use the preview site extension with an ARM template
If an ARM template is used to create and deploy apps, the Microsoft.Web/sites/siteextensions
resource type can be used to add the site extension to a web app. In the following example, the ASP.NET Core 5.0 (x64) Runtime site extension (AspNetCoreRuntime.5.0.x64
) is added to the app:
{
...
"parameters": {
"site_name": {
"defaultValue": "{SITE NAME}",
"type": "String"
},
...
},
...
"resources": [
...
{
"type": "Microsoft.Web/sites/siteextensions",
"apiVersion": "2018-11-01",
"name": "[concat(parameters('site_name'), '/AspNetCoreRuntime.5.0.x64')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('site_name'))]"
]
}
]
}
For the placeholder {SITE NAME}
, use the app's name in Azure App Service (for example, contoso
).
Publish and deploy the app
For a 64-bit 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.
Deploy the app framework-dependent
Apps published as framework-dependent are cross-platform and don't include the .NET runtime in the deployment. Azure App Service includes the .NET runtime.
- Right-click the project in Solution Explorer and select Publish. Alternatively, select Build > Publish {Application Name} from the Visual Studio toolbar.
- In the Publish dialog, select Azure > Next.
- Select the Azure service.
- Select Advanced. The Publish dialog opens.
- Select a Resource group and Hosting plan, or create new ones.
- Select Finish.
- In the Publish page:
- For Configuration, select the pen icon Edit Configuration:
- Confirm that the Release configuration is selected.
- In the Deployment Mode drop-down list, select Framework-Dependent.
- In the Target Runtime drop-down list, select the desired runtime. The default is
win-x86
.
- To remove additional files upon deployment, open File Publish Options and select the checkbox to remove additional files at the destination.
- Select Save.
- Select Publish.
- For Configuration, select the pen icon Edit Configuration:
Deploy the app self-contained
Publishing an app as self-contained produces a platform-specific executable. The output publishing folder contains all components of the app, including the .NET libraries and target runtime. For more information, see [Publish self-contained]/dotnet/core/deploying/#publish-self-contained). Use Visual Studio or the .NET CLI for a self-contained deployment (SCD).
- Right-click the project in Solution Explorer and select Publish. Alternatively, select Build > Publish {Application Name} from the Visual Studio toolbar.
- In the Publish dialog, select Azure > Next.
- Select the Azure service.
- Select Advanced. The Publish dialog opens.
- Select a Resource group and Hosting plan, or create new ones.
- Select Finish.
- In the Publish page:
- For Configuration, select the pen icon Edit Configuration:
- Confirm that the Release configuration is selected.
- In the Deployment Mode drop-down list, select Self-Contained.
- In the Target Runtime drop-down list, select the desired runtime. The default is
win-x86
.
- To remove additional files upon deployment, open File Publish Options and select the checkbox to remove additional files at the destination.
- Select Save.
- Select Publish.
- For Configuration, select the pen icon Edit Configuration:
Protocol settings (HTTPS)
Secure protocol bindings allow specifying 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
- App Service overview
- Azure App Service diagnostics overview
- Host ASP.NET Core in a web farm
- Tutorial: Connect to SQL Database from .NET App Service without secrets using a managed identity
Azure App Service on Windows Server uses Internet Information Services (IIS). Kestrel and YARP on the front end provides the load balancer. The following topics pertain to the underlying IIS technology: