|
| 1 | +--- |
| 2 | +title: Configure Aspire apps |
| 3 | +description: Learn how to configure Aspire apps deployed to Azure App Service, including App Service plan settings, Application Insights, dashboard, and health probes. |
| 4 | +ms.devlang: csharp |
| 5 | +ms.topic: how-to |
| 6 | +ms.date: 01/31/2026 |
| 7 | +author: cephalin |
| 8 | +ms.author: cephalin |
| 9 | +#customer intent: As a .NET developer, I want to configure my Aspire app deployment to Azure App Service so that I can customize the hosting infrastructure and app behavior. |
| 10 | +ms.service: azure-app-service |
| 11 | +ms.custom: |
| 12 | + - devx-track-csharp |
| 13 | + - devx-track-dotnet |
| 14 | + - devx-track-extended-azdevcli |
| 15 | +--- |
| 16 | + |
| 17 | +# Configure an Aspire app for Azure App Service |
| 18 | + |
| 19 | +This article describes how to configure [Aspire](/dotnet/aspire/get-started/aspire-overview) apps deployed to [Azure App Service](overview.md). Aspire provides a streamlined, opinionated way to build observable, production-ready cloud-native applications, and App Service integration allows you to customize the underlying Azure infrastructure through code. |
| 20 | + |
| 21 | +If you haven't deployed an Aspire app to App Service yet, see the [quickstart guide](quickstart-dotnet-aspire.md) first. |
| 22 | + |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +- An existing Aspire app with the Azure App Service hosting integration. See [Quickstart: Deploy an Aspire app to Azure App Service](quickstart-dotnet-aspire.md). |
| 26 | +- The [Aspire.Hosting.Azure.AppService](https://www.nuget.org/packages/Aspire.Hosting.Azure.AppService) package added to your AppHost project. |
| 27 | + |
| 28 | +## Understand what gets provisioned |
| 29 | + |
| 30 | +When you call `AddAzureAppServiceEnvironment`, Aspire provisions the following Azure resources by default: |
| 31 | + |
| 32 | +| Resource | Description | |
| 33 | +|----------|-------------| |
| 34 | +| **App Service Plan** | A Premium P0V3 Linux-based hosting plan | |
| 35 | +| **Azure Container Registry** | A Basic SKU registry for storing container images | |
| 36 | +| **User-assigned Managed Identity** | For secure access between App Service and Container Registry | |
| 37 | +| **Role Assignments** | ACR Pull role assigned to the managed identity | |
| 38 | + |
| 39 | +These resources provide the infrastructure needed to deploy containerized Aspire apps to Azure App Service. |
| 40 | + |
| 41 | +## Connect to an existing App Service plan |
| 42 | + |
| 43 | +If you have an existing Azure App Service plan, you can connect to it instead of provisioning a new one. Use the `AsExisting` method to reference existing resources: |
| 44 | + |
| 45 | +```csharp |
| 46 | +var builder = DistributedApplication.CreateBuilder(args); |
| 47 | + |
| 48 | +var existingAppServicePlanName = builder.AddParameter("existingAppServicePlanName"); |
| 49 | +var existingResourceGroup = builder.AddParameter("existingResourceGroup"); |
| 50 | + |
| 51 | +var appServiceEnv = builder.AddAzureAppServiceEnvironment("app-service-env") |
| 52 | + .AsExisting(existingAppServicePlanName, existingResourceGroup); |
| 53 | + |
| 54 | +builder.AddProject<Projects.WebApi>("api") |
| 55 | + .PublishAsAzureAppServiceWebsite((infra, website) => |
| 56 | + { |
| 57 | + // Optional: customize the Azure App Service website here |
| 58 | + }); |
| 59 | + |
| 60 | +builder.Build().Run(); |
| 61 | +``` |
| 62 | + |
| 63 | +This approach is useful when you want to: |
| 64 | + |
| 65 | +- Share an App Service plan across multiple applications |
| 66 | +- Use an App Service plan that was provisioned outside of Aspire |
| 67 | +- Connect to resources in a different resource group |
| 68 | + |
| 69 | +## Publish projects as App Service websites |
| 70 | + |
| 71 | +Use the `PublishAsAzureAppServiceWebsite` method to deploy compute resources as Azure App Service websites: |
| 72 | + |
| 73 | +```csharp |
| 74 | +var builder = DistributedApplication.CreateBuilder(args); |
| 75 | + |
| 76 | +var appServiceEnv = builder.AddAzureAppServiceEnvironment("app-service-env"); |
| 77 | + |
| 78 | +builder.AddProject<Projects.WebApi>("api") |
| 79 | + .PublishAsAzureAppServiceWebsite((infra, website) => |
| 80 | + { |
| 81 | + // Optional: customize the Azure App Service website here |
| 82 | + }); |
| 83 | + |
| 84 | +builder.Build().Run(); |
| 85 | +``` |
| 86 | + |
| 87 | +During local development (when running with F5 or `dotnet run`), the project runs locally. When you publish your app with `azd up`, the project is deployed as an Azure App Service website within the provisioned environment. |
| 88 | + |
| 89 | +## Configure App Service plan SKU and tier |
| 90 | + |
| 91 | +You can customize the App Service plan SKU, tier, and capacity by using the `ConfigureInfrastructure` method. This approach lets you access and modify the underlying Azure resources that Aspire provisions. |
| 92 | + |
| 93 | +In your *AppHost.cs* file, configure the App Service environment with custom plan settings: |
| 94 | + |
| 95 | +```csharp |
| 96 | +using Azure.Provisioning.AppService; |
| 97 | + |
| 98 | +var builder = DistributedApplication.CreateBuilder(args); |
| 99 | + |
| 100 | +builder.AddAzureAppServiceEnvironment("app-service-env") |
| 101 | + .ConfigureInfrastructure((infra) => |
| 102 | + { |
| 103 | + var plan = infra.GetProvisionableResources().OfType<AppServicePlan>().Single(); |
| 104 | + plan.Sku = new AppServiceSkuDescription |
| 105 | + { |
| 106 | + Name = "P1V3", |
| 107 | + Tier = "Premium" |
| 108 | + }; |
| 109 | + }); |
| 110 | + |
| 111 | +builder.Build().Run(); |
| 112 | +``` |
| 113 | + |
| 114 | +The `ConfigureInfrastructure` callback gives you direct access to the Azure provisioning resources. In this example: |
| 115 | + |
| 116 | +- `GetProvisionableResources()` returns all Azure resources being provisioned. |
| 117 | +- `OfType<AppServicePlan>()` filters to get the App Service plan. |
| 118 | +- You can then modify properties like `Sku.Name`, `Sku.Tier`, and `Sku.Capacity` (number of instances). |
| 119 | + |
| 120 | +## Configure the Aspire Dashboard |
| 121 | + |
| 122 | +The Aspire Dashboard is included by default when deploying to Azure App Service, giving you visibility into your deployed applications: |
| 123 | + |
| 124 | +```csharp |
| 125 | +builder.AddAzureAppServiceEnvironment("app-service-env"); |
| 126 | +// Dashboard is included by default at https://[prefix]-aspiredashboard-[unique string].azurewebsites.net |
| 127 | +``` |
| 128 | + |
| 129 | +The deployed dashboard provides the same experience as local development: view logs, traces, metrics, and application topology for your production environment. |
| 130 | + |
| 131 | +To disable the dashboard: |
| 132 | + |
| 133 | +```csharp |
| 134 | +builder.AddAzureAppServiceEnvironment("app-service-env") |
| 135 | + .WithDashboard(enable: false); |
| 136 | +``` |
| 137 | + |
| 138 | +## Configure Azure Application Insights |
| 139 | + |
| 140 | +Enable Azure Application Insights for comprehensive monitoring and telemetry: |
| 141 | + |
| 142 | +```csharp |
| 143 | +builder.AddAzureAppServiceEnvironment("app-service-env") |
| 144 | + .WithAzureApplicationInsights(); |
| 145 | +``` |
| 146 | + |
| 147 | +When enabled, Aspire automatically: |
| 148 | + |
| 149 | +- Creates a Log Analytics workspace. |
| 150 | +- Creates an Application Insights resource. |
| 151 | +- Configures all App Service web apps with the connection string. |
| 152 | +- Injects `APPLICATIONINSIGHTS_CONNECTION_STRING` into your applications. |
| 153 | + |
| 154 | +You can also reference an existing Application Insights resource: |
| 155 | + |
| 156 | +```csharp |
| 157 | +var insights = builder.AddAzureApplicationInsights("insights"); |
| 158 | + |
| 159 | +builder.AddAzureAppServiceEnvironment("app-service-env") |
| 160 | + .WithAzureApplicationInsights(insights); |
| 161 | +``` |
| 162 | + |
| 163 | +## Configure app settings |
| 164 | + |
| 165 | +You can add custom app settings to your App Service apps by using the `PublishAsAzureAppServiceWebsite` method with infrastructure configuration. |
| 166 | + |
| 167 | +```csharp |
| 168 | +builder.AddProject<Projects.aspire_starter_Web>("webfrontend") |
| 169 | + .WithExternalHttpEndpoints() |
| 170 | + .WithReference(apiService) |
| 171 | + .WaitFor(apiService) |
| 172 | + .PublishAsAzureAppServiceWebsite((infra, website) => |
| 173 | + { |
| 174 | + website.SiteConfig.AppSettings.Add(new AppServiceNameValuePair |
| 175 | + { |
| 176 | + Name = "WEBSITE_LOAD_CERTIFICATES", |
| 177 | + Value = "*" |
| 178 | + }); |
| 179 | + website.SiteConfig.AppSettings.Add(new AppServiceNameValuePair |
| 180 | + { |
| 181 | + Name = "MyCustomSetting", |
| 182 | + Value = "MyCustomValue" |
| 183 | + }); |
| 184 | + }); |
| 185 | +``` |
| 186 | + |
| 187 | +You can add any App Service app settings through the `SiteConfig.AppSettings` collection. |
| 188 | + |
| 189 | +## Add tags to resources |
| 190 | + |
| 191 | +Tags help you organize and manage your Azure resources. You can add tags to both websites and the App Service plan. |
| 192 | + |
| 193 | +Add tags to a website: |
| 194 | + |
| 195 | +```csharp |
| 196 | +builder.AddProject<Projects.aspire_starter_Web>("webfrontend") |
| 197 | + .PublishAsAzureAppServiceWebsite((infra, website) => |
| 198 | + { |
| 199 | + website.Tags.Add("Environment", "Production"); |
| 200 | + website.Tags.Add("Team", "Engineering"); |
| 201 | + }); |
| 202 | +``` |
| 203 | + |
| 204 | +Add tags to the App Service plan: |
| 205 | + |
| 206 | +```csharp |
| 207 | +builder.AddAzureAppServiceEnvironment("app-service-env") |
| 208 | + .ConfigureInfrastructure(infra => |
| 209 | + { |
| 210 | + var plan = infra.GetProvisionableResources().OfType<AppServicePlan>().Single(); |
| 211 | + plan.Tags.Add("Environment", "Production"); |
| 212 | + plan.Tags.Add("CostCenter", "Engineering"); |
| 213 | + }); |
| 214 | +``` |
| 215 | + |
| 216 | +## Configure health probes |
| 217 | + |
| 218 | +Health probes allow Azure App Service to monitor your application's health and make routing decisions. You can configure different probe types using the `WithHttpProbe` method. |
| 219 | + |
| 220 | +```csharp |
| 221 | +#pragma warning disable ASPIREPROBES001 |
| 222 | +builder.AddProject<Projects.aspire_starter_Web>("webfrontend") |
| 223 | + .WithHttpProbe(ProbeType.Liveness, "/healthz") |
| 224 | + // ... other configuration |
| 225 | +#pragma warning restore ASPIREPROBES001 |
| 226 | +``` |
| 227 | + |
| 228 | +> [!NOTE] |
| 229 | +> Using `WithHttpProbe` may require suppressing the `ASPIREPROBES001` diagnostic warning, as this feature is in preview. |
| 230 | +
|
| 231 | +Make sure your application exposes the health check endpoints. For ASP.NET Core apps, you can use the built-in health checks middleware: |
| 232 | + |
| 233 | +```csharp |
| 234 | +var builder = WebApplication.CreateBuilder(args); |
| 235 | + |
| 236 | +builder.Services.AddHealthChecks(); |
| 237 | + |
| 238 | +var app = builder.Build(); |
| 239 | + |
| 240 | +app.MapHealthChecks("/healthz"); |
| 241 | + |
| 242 | +app.Run(); |
| 243 | +``` |
| 244 | + |
| 245 | +## Configure external endpoints |
| 246 | + |
| 247 | +When deploying Aspire apps to App Service, service-to-service communication requires external HTTP endpoints. Unlike Container Apps, App Service currently doesn't manage traffic between apps through internal endpoints. |
| 248 | + |
| 249 | +```csharp |
| 250 | +var apiService = builder.AddProject<Projects.aspire_starter_ApiService>("apiservice") |
| 251 | + .WithExternalHttpEndpoints() |
| 252 | + .WithHttpHealthCheck("/health"); |
| 253 | + |
| 254 | +builder.AddProject<Projects.aspire_starter_Web>("webfrontend") |
| 255 | + .WithExternalHttpEndpoints() |
| 256 | + .WithReference(apiService) |
| 257 | + .WaitFor(apiService); |
| 258 | +``` |
| 259 | + |
| 260 | +The `WithExternalHttpEndpoints()` method configures the project to be accessible via public HTTP endpoints. This is required for: |
| 261 | + |
| 262 | +- Backend services that other services in your Aspire app need to call |
| 263 | +- Frontend applications that users access directly |
| 264 | + |
| 265 | +## Related content |
| 266 | + |
| 267 | +- [Quickstart: Deploy an Aspire app to Azure App Service](quickstart-dotnet-aspire.md) |
| 268 | +- [Aspire documentation](/dotnet/aspire/) |
| 269 | +- [Azure App Service integration for Aspire](https://www.nuget.org/packages/Aspire.Hosting.Azure.AppService) |
| 270 | +- [Configure an ASP.NET Core app for Azure App Service](configure-language-dotnetcore.md) |
0 commit comments