Skip to content
DocsTry Aspire
DocsTry

AzureAppServiceEnvironmentExtensions Methods

ClassMethods10 members
Extensions for adding Azure App Service Environment resources to a distributed application builder.
AddAzureAppServiceEnvironment(IDistributedApplicationBuilder, string)Section titled AddAzureAppServiceEnvironment(IDistributedApplicationBuilder, string)extensionIResourceBuilder<AzureAppServiceEnvironmentResource>
Adds a azure app service environment resource to the distributed application builder.
public static class AzureAppServiceEnvironmentExtensions
{
public static IResourceBuilder<AzureAppServiceEnvironmentResource> AddAzureAppServiceEnvironment(
this IDistributedApplicationBuilder builder,
string name)
{
// ...
}
}
builderIDistributedApplicationBuilderThe distributed application builder.
namestringThe name of the resource.
IResourceBuilder<AzureAppServiceEnvironmentResource>ApplicationModel.IResourceBuilder`1
WithAcrPullIdentity(IResourceBuilder<AzureAppServiceEnvironmentResource>, IResourceBuilder<AzureUserAssignedIdentityResource>)Section titled WithAcrPullIdentity(IResourceBuilder<AzureAppServiceEnvironmentResource>, IResourceBuilder<AzureUserAssignedIdentityResource>)extensionIResourceBuilder<AzureAppServiceEnvironmentResource>
Configures the Azure App Service environment to use the supplied Azure.AzureUserAssignedIdentityResource as the managed identity that App Service apps use to pull images from the configured container registry (the AcrPull identity), instead of having Aspire create a new identity and a new AcrPull role assignment.
public static class AzureAppServiceEnvironmentExtensions
{
public static IResourceBuilder<AzureAppServiceEnvironmentResource> WithAcrPullIdentity(
this IResourceBuilder<AzureAppServiceEnvironmentResource> builder,
IResourceBuilder<AzureUserAssignedIdentityResource> identityBuilder)
{
// ...
}
}
builderIResourceBuilder<AzureAppServiceEnvironmentResource>The Azure App Service environment to configure.
identityBuilderIResourceBuilder<AzureUserAssignedIdentityResource> The resource builder for the user-assigned identity that should be used for image pulls. The supplied identity must already have the AcrPull role on the configured container registry.
IResourceBuilder<AzureAppServiceEnvironmentResource>The ApplicationModel.IResourceBuilder`1 for chaining.
ArgumentNullExceptionThrown when builder or identityBuilder is null.

When this is set, Aspire will not create a new identity or an AcrPull role assignment for the container registry. The caller is responsible for ensuring the supplied identity already has the required AcrPull role assignment on the registry, for example by chaining .WithRoleAssignments(acr, ContainerRegistryBuiltInRole.AcrPull) when adding the identity.

Unlike the equivalent method on Azure Container Apps, App Service reuses this single identity for more than just image pulls. The same identity is also attached to every generated App Service web app as a user-assigned managed identity, and is used by the Aspire OTLP sidecar to authenticate telemetry to the Aspire dashboard (it is added to the dashboard's ALLOWED_MANAGED_IDENTITIES and exposed to each app via the OTEL client-id app setting). If you supply an existing identity here, it will take on all of these roles.

This is commonly combined with AsExisting on the App Service environment (App Service Plan) and on the container registry to deploy websites into a pre-provisioned set of Azure resources without Aspire emitting any new ACR-pull identity or ACR-pull role-assignment resources. See https://github.com/microsoft/aspire/issues/14382 for the scenario this addresses.

Only the combination of an existing App Service Plan, an existing container registry, and this method avoids emitting any new identity or role-assignment resources in the env module. Other combinations still work but will emit additional resources:

  • If the App Service Plan is marked AsExisting but no identity is supplied here, Aspire still emits a new UserAssignedIdentity and an AcrPull role assignment on the configured registry.
  • If this method is used but the container registry is not existing (either the Aspire-generated default registry or a user-added registry without AsExisting), the registry itself is still provisioned. To wire the supplied identity to that newly-created registry, chain .WithRoleAssignments(acr, ContainerRegistryBuiltInRole.AcrPull) on the identity.

If the Aspire dashboard is enabled, Aspire still provisions the dashboard website and its contributor identity. Use AzureAppServiceEnvironmentExtensions.WithDashboard with false when targeting a fully pre-provisioned App Service Plan that should not receive a dashboard.

WithAzureApplicationInsights(IResourceBuilder<AzureAppServiceEnvironmentResource>)Section titled WithAzureApplicationInsights(IResourceBuilder<AzureAppServiceEnvironmentResource>)extensionIResourceBuilder<AzureAppServiceEnvironmentResource>
Configures whether Azure Application Insights should be enabled for the Azure App Service.
public static class AzureAppServiceEnvironmentExtensions
{
public static IResourceBuilder<AzureAppServiceEnvironmentResource> WithAzureApplicationInsights(
this IResourceBuilder<AzureAppServiceEnvironmentResource> builder)
{
// ...
}
}
builderIResourceBuilder<AzureAppServiceEnvironmentResource>The AzureAppServiceEnvironmentResource to configure.
IResourceBuilder<AzureAppServiceEnvironmentResource>ApplicationModel.IResourceBuilder`1
WithAzureApplicationInsights(IResourceBuilder<AzureAppServiceEnvironmentResource>, string)Section titled WithAzureApplicationInsights(IResourceBuilder<AzureAppServiceEnvironmentResource>, string)extensionIResourceBuilder<AzureAppServiceEnvironmentResource>
Configures whether Azure Application Insights should be enabled for the Azure App Service.
public static class AzureAppServiceEnvironmentExtensions
{
public static IResourceBuilder<AzureAppServiceEnvironmentResource> WithAzureApplicationInsights(
this IResourceBuilder<AzureAppServiceEnvironmentResource> builder,
string applicationInsightsLocation)
{
// ...
}
}
builderIResourceBuilder<AzureAppServiceEnvironmentResource>The AzureAppServiceEnvironmentResource to configure.
applicationInsightsLocationstringThe location for Application Insights.
IResourceBuilder<AzureAppServiceEnvironmentResource>ApplicationModel.IResourceBuilder`1
WithAzureApplicationInsights(IResourceBuilder<AzureAppServiceEnvironmentResource>, IResourceBuilder<ParameterResource>)Section titled WithAzureApplicationInsights(IResourceBuilder<AzureAppServiceEnvironmentResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<AzureAppServiceEnvironmentResource>
Configures whether Azure Application Insights should be enabled for the Azure App Service.
public static class AzureAppServiceEnvironmentExtensions
{
public static IResourceBuilder<AzureAppServiceEnvironmentResource> WithAzureApplicationInsights(
this IResourceBuilder<AzureAppServiceEnvironmentResource> builder,
IResourceBuilder<ParameterResource> applicationInsightsLocation)
{
// ...
}
}
builderIResourceBuilder<AzureAppServiceEnvironmentResource>The AzureAppServiceEnvironmentResource to configure.
applicationInsightsLocationIResourceBuilder<ParameterResource>The location parameter for Application Insights.
IResourceBuilder<AzureAppServiceEnvironmentResource>ApplicationModel.IResourceBuilder`1
WithAzureApplicationInsights(IResourceBuilder<AzureAppServiceEnvironmentResource>, IResourceBuilder<AzureApplicationInsightsResource>)Section titled WithAzureApplicationInsights(IResourceBuilder<AzureAppServiceEnvironmentResource>, IResourceBuilder<AzureApplicationInsightsResource>)extensionIResourceBuilder<AzureAppServiceEnvironmentResource>
Configures whether Azure Application Insights should be enabled for the Azure App Service.
public static class AzureAppServiceEnvironmentExtensions
{
public static IResourceBuilder<AzureAppServiceEnvironmentResource> WithAzureApplicationInsights(
this IResourceBuilder<AzureAppServiceEnvironmentResource> builder,
IResourceBuilder<AzureApplicationInsightsResource> applicationInsightsBuilder)
{
// ...
}
}
builderIResourceBuilder<AzureAppServiceEnvironmentResource>The AzureAppServiceEnvironmentResource builder to configure.
applicationInsightsBuilderIResourceBuilder<AzureApplicationInsightsResource>The Application Insights resource builder.
IResourceBuilder<AzureAppServiceEnvironmentResource>ApplicationModel.IResourceBuilder`1
WithDashboard(IResourceBuilder<AzureAppServiceEnvironmentResource>, bool)Section titled WithDashboard(IResourceBuilder<AzureAppServiceEnvironmentResource>, bool)extensionIResourceBuilder<AzureAppServiceEnvironmentResource>
Configures whether the Aspire dashboard should be included in the Azure App Service environment.
public static class AzureAppServiceEnvironmentExtensions
{
public static IResourceBuilder<AzureAppServiceEnvironmentResource> WithDashboard(
this IResourceBuilder<AzureAppServiceEnvironmentResource> builder,
bool enable = true)
{
// ...
}
}
builderIResourceBuilder<AzureAppServiceEnvironmentResource>The ApplicationModel.IResourceBuilder`1 to configure.
enablebooloptionalWhether to include the Aspire dashboard. Default is true.
IResourceBuilder<AzureAppServiceEnvironmentResource>A reference to the ApplicationModel.IResourceBuilder`1 for chaining additional configuration.
WithDeploymentSlot(IResourceBuilder<AzureAppServiceEnvironmentResource>, IResourceBuilder<ParameterResource>)Section titled WithDeploymentSlot(IResourceBuilder<AzureAppServiceEnvironmentResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<AzureAppServiceEnvironmentResource>
Configures the slot to which the Azure App Services should be deployed.
public static class AzureAppServiceEnvironmentExtensions
{
public static IResourceBuilder<AzureAppServiceEnvironmentResource> WithDeploymentSlot(
this IResourceBuilder<AzureAppServiceEnvironmentResource> builder,
IResourceBuilder<ParameterResource> deploymentSlot)
{
// ...
}
}
builderIResourceBuilder<AzureAppServiceEnvironmentResource>The AzureAppServiceEnvironmentResource to configure.
deploymentSlotIResourceBuilder<ParameterResource>The deployment slot parameter for all App Services in the App Service Environment.
IResourceBuilder<AzureAppServiceEnvironmentResource>ApplicationModel.IResourceBuilder`1
WithDeploymentSlot(IResourceBuilder<AzureAppServiceEnvironmentResource>, string)Section titled WithDeploymentSlot(IResourceBuilder<AzureAppServiceEnvironmentResource>, string)extensionIResourceBuilder<AzureAppServiceEnvironmentResource>
Configures the slot to which the Azure App Services should be deployed.
public static class AzureAppServiceEnvironmentExtensions
{
public static IResourceBuilder<AzureAppServiceEnvironmentResource> WithDeploymentSlot(
this IResourceBuilder<AzureAppServiceEnvironmentResource> builder,
string deploymentSlot)
{
// ...
}
}
builderIResourceBuilder<AzureAppServiceEnvironmentResource>The AzureAppServiceEnvironmentResource to configure.
deploymentSlotstringThe deployment slot for all App Services in the App Service Environment.
IResourceBuilder<AzureAppServiceEnvironmentResource>ApplicationModel.IResourceBuilder`1
WithHttpsUpgrade(IResourceBuilder<AzureAppServiceEnvironmentResource>, bool)Section titled WithHttpsUpgrade(IResourceBuilder<AzureAppServiceEnvironmentResource>, bool)extensionIResourceBuilder<AzureAppServiceEnvironmentResource>
Configures whether HTTP endpoints should be automatically upgraded to HTTPS for the Azure App Service environment. By default, HTTP endpoints are upgraded to HTTPS for security and WebSocket compatibility.
public static class AzureAppServiceEnvironmentExtensions
{
public static IResourceBuilder<AzureAppServiceEnvironmentResource> WithHttpsUpgrade(
this IResourceBuilder<AzureAppServiceEnvironmentResource> builder,
bool upgrade = true)
{
// ...
}
}
builderIResourceBuilder<AzureAppServiceEnvironmentResource>The ApplicationModel.IResourceBuilder`1 to configure.
upgradebooloptionalWhether to upgrade HTTP endpoints to HTTPS. Default is true.
IResourceBuilder<AzureAppServiceEnvironmentResource>A reference to the ApplicationModel.IResourceBuilder`1 for chaining additional configuration.
When disabled ( false), HTTP endpoints will use HTTP scheme and port 80 in Azure App Service. Note that Azure App Service forces HTTP to HTTPS redirects at the platform level, so disabling upgrade primarily affects connection strings generated for dependent resources.

Preserve HTTP endpoints instead of automatically upgrading them to HTTPS:

var appService = builder.AddAzureAppServiceEnvironment("appservice")
.WithHttpsUpgrade(false);