Share via


ResourceBuilderExtensions.WithUrlForEndpoint Method

Definition

Overloads

WithUrlForEndpoint<T>(IResourceBuilder<T>, String, Action<ResourceUrlAnnotation>)

Registers a callback to update the URL displayed for the endpoint with the specified name.

WithUrlForEndpoint<T>(IResourceBuilder<T>, String, Func<EndpointReference,ResourceUrlAnnotation>)

Registers a callback to add a URL for the endpoint with the specified name.

WithUrlForEndpoint<T>(IResourceBuilder<T>, String, Action<ResourceUrlAnnotation>)

Source:
ResourceBuilderExtensions.cs
Source:
ResourceBuilderExtensions.cs

Registers a callback to update the URL displayed for the endpoint with the specified name.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithUrlForEndpoint<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, string endpointName, Action<Aspire.Hosting.ApplicationModel.ResourceUrlAnnotation> callback) where T : Aspire.Hosting.ApplicationModel.IResource;
static member WithUrlForEndpoint : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)> * string * Action<Aspire.Hosting.ApplicationModel.ResourceUrlAnnotation> -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)> (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)
<Extension()>
Public Function WithUrlForEndpoint(Of T As IResource) (builder As IResourceBuilder(Of T), endpointName As String, callback As Action(Of ResourceUrlAnnotation)) As IResourceBuilder(Of T)

Type Parameters

T

The resource type.

Parameters

builder
IResourceBuilder<T>

The builder for the resource.

endpointName
String

The name of the endpoint to customize the URL for.

callback
Action<ResourceUrlAnnotation>

The callback that will customize the URL.

Returns

The IResourceBuilder<T>.

Examples

Customize the URL for the "https" endpoint to use the link text "Home":

var frontend = builder.AddProject<Projects.Frontend>("frontend")
                      .WithUrlForEndpoint("https", url => url.DisplayText = "Home");

Remarks

Use this method to customize the URL that is automatically added for an endpoint on the resource.
To add another URL for an endpoint, use WithUrlForEndpoint<T>(IResourceBuilder<T>, String, Func<EndpointReference,ResourceUrlAnnotation>).

The callback will be executed after endpoints have been allocated and the URL has been generated.
This allows you to modify the URL or its display text.

If the URL returned by callback is relative, it will be combined with the endpoint URL to create an absolute URL.

If the endpoint with the specified name does not exist, the callback will not be executed and a warning will be logged.

Customize the URL for the "https" endpoint to use the link text "Home":
var frontend = builder.AddProject<Projects.Frontend>("frontend")
                      .WithUrlForEndpoint("https", url => url.DisplayText = "Home");
Customize the URL for the "https" endpoint to deep to the "/home" path:
var frontend = builder.AddProject<Projects.Frontend>("frontend")
                      .WithUrlForEndpoint("https", url => url.Url = "/home");

Applies to

WithUrlForEndpoint<T>(IResourceBuilder<T>, String, Func<EndpointReference,ResourceUrlAnnotation>)

Source:
ResourceBuilderExtensions.cs

Registers a callback to add a URL for the endpoint with the specified name.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithUrlForEndpoint<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, string endpointName, Func<Aspire.Hosting.ApplicationModel.EndpointReference,Aspire.Hosting.ApplicationModel.ResourceUrlAnnotation> callback) where T : Aspire.Hosting.ApplicationModel.IResourceWithEndpoints;
static member WithUrlForEndpoint : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithEndpoints)> * string * Func<Aspire.Hosting.ApplicationModel.EndpointReference, Aspire.Hosting.ApplicationModel.ResourceUrlAnnotation> -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithEndpoints)> (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithEndpoints)
<Extension()>
Public Function WithUrlForEndpoint(Of T As IResourceWithEndpoints) (builder As IResourceBuilder(Of T), endpointName As String, callback As Func(Of EndpointReference, ResourceUrlAnnotation)) As IResourceBuilder(Of T)

Type Parameters

T

The resource type.

Parameters

builder
IResourceBuilder<T>

The builder for the resource.

endpointName
String

The name of the endpoint to add the URL for.

callback
Func<EndpointReference,ResourceUrlAnnotation>

The callback that will create the URL.

Returns

The IResourceBuilder<T>.

Remarks

Use this method to add another URL for an endpoint on the resource.
To customize the URL that is automatically added for an endpoint, use WithUrlForEndpoint<T>(IResourceBuilder<T>, String, Action<ResourceUrlAnnotation>).

The callback will be executed after endpoints have been allocated and the resource is about to start.

If the endpoint with the specified name does not exist, the callback will not be executed and a warning will be logged.

Add a URL for the "https" endpoint that deep-links to an admin page with the text "Admin":
var frontend = builder.AddProject<Projects.Frontend>("frontend")
                      .WithUrlForEndpoint("https", ep => new() { Url = "/admin", DisplayText = "Admin" });

Applies to