# AzureFrontDoorPrivateLinkExtensions Methods

- Package: [Aspire.Hosting.Azure.FrontDoor](/reference/api/csharp/aspire.hosting.azure.frontdoor.md)
- Type: [AzureFrontDoorPrivateLinkExtensions](/reference/api/csharp/aspire.hosting.azure.frontdoor/azurefrontdoorprivatelinkextensions.md)
- Kind: `Methods`
- Members: `1`

Extension methods for reaching Azure Container Apps or Azure App Service through Azure Front Door Private Link.

<a id="withazurefrontdoorprivatelink"></a>
<a id="withazurefrontdoorprivatelink-iresourcebuilder-t-iresourcebuilder-azurefrontdoorresource"></a>

## WithAzureFrontDoorPrivateLink(IResourceBuilder<T>, IResourceBuilder<AzureFrontDoorResource>)

> **Experimental:** ASPIREAZURE003 - [Learn more](/diagnostics/aspireazure003/)

- Name: `WithAzureFrontDoorPrivateLink(IResourceBuilder<T>, IResourceBuilder<AzureFrontDoorResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<T>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting.Azure.FrontDoor/AzureFrontDoorPrivateLinkExtensions.cs#L131-L153)

Connects an Azure Front Door to a compute environment, such as an Azure Container Apps environment, over Private Link and disables public network access to its apps, so that the apps in the environment are reachable only through the Front Door.

```csharp
public static class AzureFrontDoorPrivateLinkExtensions
{
    public static IResourceBuilder<T> WithAzureFrontDoorPrivateLink<T>(
        this IResourceBuilder<T> environment,
        IResourceBuilder<AzureFrontDoorResource> frontDoor)
    {
        // ...
    }
}
```

## Parameters

- `environment` (`IResourceBuilder<T>`)
  The compute environment to connect to.
- `frontDoor` (`IResourceBuilder<AzureFrontDoorResource>`)
  The Azure Front Door, created with [AzureFrontDoorExtensions.AddAzureFrontDoor(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting.azure.frontdoor/azurefrontdoorextensions/methods.md#addazurefrontdoor-idistributedapplicationbuilder-string), whose origins in `environment` use Private Link.

## Returns

`IResourceBuilder<T>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for `environment`, for chaining.

## Exceptions

- `ArgumentNullException` -- `environment` or `frontDoor` is `null`.
- `InvalidOperationException` -- Publishing fails for existing or Express Container Apps environments, when `frontDoor` has no origin in the environment, and when another Front Door has an origin in the environment without being connected to it.

## Remarks

Add the apps to the Front Door with [AzureFrontDoorExtensions.WithOrigin(IResourceBuilder<AzureFrontDoorResource>, IResourceBuilder<T>)](/reference/api/csharp/aspire.hosting.azure.frontdoor/azurefrontdoorextensions/methods.md#withorigin-iresourcebuilder-azurefrontdoorresource-iresourcebuilder-t), before or after this call. When publishing, every origin of `frontDoor` that runs in `environment` becomes a Private Link origin: the Front Door profile uses the Premium SKU, and the origin connects to the environment through a Front Door managed private endpoint. The apps must expose external HTTP endpoints, for example with `WithExternalHttpEndpoints`. Origins in other compute environments are left as they are.

Like a private endpoint to any other Azure resource, the Private Link disables public network access to the environment. Apps in the environment are no longer reachable from the Internet except through Front Door. Callers outside the environment must reach the apps through the Front Door, or through a route of their own.

An Azure Container Apps environment can only have its public network access disabled when Aspire provisions it, so it can't be marked as existing, and it must be a workload profiles environment, not an [Azure Container Apps Express](https://learn.microsoft.com/azure/container-apps/express-overview) environment.

For Azure App Service, each origin targets its own website with the `sites` group ID, not the App Service plan. Public network access is disabled on all workload websites in the connected environment, including websites that are not Front Door origins. The separately provisioned Aspire dashboard is unchanged. Existing App Service plans are supported because Aspire still provisions the websites. Front Door Private Link cannot target a deployment slot, so with `WithDeploymentSlot` each origin targets the production site and the slot, which has public access disabled and no private endpoint, is not reachable through Front Door: deploy to the slot and swap it into production. The production site is created only if it does not exist, so enabling this on a site that already exists doesn't disable its public access. Unlike Container Apps, App Service does not provide an environment-local ingress route between apps: service-to-service callers must use Front Door URLs or configure their own private network access and DNS.

Front Door creates a connection request in the Pending state, and no traffic reaches the apps until the owner of the target approves it. Approve it in the Azure portal, under the Container Apps environment's or each App Service website's networking settings, or with the Azure CLI by finding the request with `az network private-endpoint-connection list` and approving it with `az network private-endpoint-connection approve`. Front Door can create more than one request; approve each one that has the message of this connection. Traffic starts flowing a few minutes after approval.

Front Door creates its private endpoint in the region of `environment`. Front Door Private Link is only available in some [regions](https://learn.microsoft.com/azure/frontdoor/private-link#region-availability), so for an environment in another region the private endpoint is created in the supported region of the same geography, such as `westus2` for `westus`, at the cost of an extra network hop. Deployment fails when the geography has no supported region. To choose another region, set the origin's `SharedPrivateLinkResource.PrivateLinkLocation` in `AzureProvisioningResourceExtensions.ConfigureInfrastructure` on `frontDoor`, for example to a parameter.

Private Link has no run-mode counterpart, so this method does nothing when the AppHost runs locally.

## Examples

```csharp
var environment = builder.AddAzureContainerAppEnvironment("env");
var frontDoor = builder.AddAzureFrontDoor("frontdoor");
environment.WithAzureFrontDoorPrivateLink(frontDoor);

var api = builder.AddDotnetProject("api", "../Api/Api.csproj")
    .WithExternalHttpEndpoints();
var web = builder.AddDotnetProject("web", "../Web/Web.csproj")
    .WithExternalHttpEndpoints()
    .WithReference(api);
frontDoor.WithOrigin(api).WithOrigin(web);
```

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting.Azure.FrontDoor/withFrontDoorAzureFrontDoorPrivateLink`
- Generated method name override: `withAzureFrontDoorPrivateLink`
