-
Notifications
You must be signed in to change notification settings - Fork 168
Add content on customizing resource URLs #2940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
974105d
Fixes #2936
IEvangelist 109ce98
Correct TOC
IEvangelist 8f56363
Minor tweaks
IEvangelist a397879
Apply suggestions from code review
IEvangelist be4436d
Apply suggestions from code review
IEvangelist b0773f4
Apply suggestions from code review
IEvangelist bf83ae0
Apply suggestions from code review
IEvangelist 1d493c5
Apply suggestions from code review
IEvangelist 57e8000
Apply suggestions from code review
IEvangelist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| --- | ||
| title: Define custom resource URLs | ||
| description: Learn how to create custom URLs for .NET Aspire resources. | ||
| ms.date: 04/08/2025 | ||
| ms.topic: how-to | ||
| --- | ||
|
|
||
| # Define custom resource URLs | ||
|
|
||
| In .NET Aspire, resources that expose endpoints only configure host and port, which aren't known until run time. If you need to access a specific path on one of these endpoints—especially from the [dashboard](dashboard/overview.md)—you can define custom resource URLs. You can also add custom URLs that aren't tied to any endpoint. All custom URLs are only available in "run" mode, since they're meant for dashboard use. This article demonstrates how to define custom URLs. | ||
|
|
||
| ## Default endpoint behavior | ||
|
|
||
| By default, .NET Aspire project resources rely on existing configurations such as Kestrel or launch profiles to determine the host and port of a resource for a configured endpoint. | ||
|
|
||
| Likewise, you can explicitly expose endpoints using the <xref:Aspire.Hosting.ResourceBuilderExtensions.WithEndpoint*> API. This API allows you to specify the host and port for a resource, which is then used to create the default URL for that resource. The default URL is typically in the format `http://<host>:<port>` or `https://<host>:<port>`, depending on the protocol used. To omit the host port, use one of the following methods: | ||
|
|
||
| - <xref:Aspire.Hosting.ResourceBuilderExtensions.WithHttpEndpoint*> | ||
| - <xref:Aspire.Hosting.ResourceBuilderExtensions.WithHttpsEndpoint*> | ||
|
|
||
| For more information, see [Endpoint extension methods](networking-overview.md#endpoint-extension-methods). | ||
|
|
||
| ## Supported resource types | ||
|
|
||
| Currently, custom resource URLs are supported for the following resource types: | ||
|
|
||
| - <xref:Aspire.Hosting.ApplicationModel.ContainerResource> | ||
| - <xref:Aspire.Hosting.ApplicationModel.ExecutableResource> | ||
| - <xref:Aspire.Hosting.ApplicationModel.ProjectResource> | ||
|
|
||
| ## Customize resource URLs | ||
|
|
||
| Use the appropriate `WithUrl` overload, `WithUrls`, or `WithUrlForEndpoint` APIs on any supported resource builder to define custom URLs for a resource. The following example demonstrates how to set a custom URL for a project resource: | ||
|
|
||
| :::code source="snippets/custom-urls/AspireApp.AppHost/Program.WithUrl.cs" id="withurl"::: | ||
|
|
||
| > [!TIP] | ||
| > There's an overload that accepts a `string` allowing you to pass any URL. This is useful for defining custom URLs that aren't directly related to the resource's endpoint. | ||
|
|
||
| The preceding code assigns a project reference to the `api` variable, which is then used to create a custom URL for the `Admin Portal` route. The `WithUrl` method takes a <xref:Aspire.Hosting.ApplicationModel.ReferenceExpression> and a display name as parameters. The resulting URL is available in the dashboard as shown in the following screenshot: | ||
|
|
||
| :::image type="content" source="dashboard/media/custom-urls/custom-url-admin-portal.png" alt-text=".NET Aspire dashboard custom Admin Portal URL." lightbox="dashboard/media/custom-urls/custom-url-admin-portal.png"::: | ||
|
|
||
| ### Customize endpoint URL | ||
|
|
||
| <!-- TODO: Add xref to WithUrlForEndpoint when available --> | ||
|
|
||
| Both [Scalar](https://scalar.com/) and [Swagger](https://swagger.io/tools/swagger-ui/) are common API services that enhance the usability of endpoints. These services are accessed via URLs tied to declared endpoints. | ||
|
|
||
| To customize the URL for the first associated resource endpoint, use the `WithUrlForEndpoint` method. | ||
|
|
||
| If you want to add a separate URL (even for the same endpoint) you need to call the `WithUrl` overload that takes a `ReferenceExpression` or interpolated string, or call `WithUrls` and add the URL to the `Urls` list on the context. | ||
|
|
||
| :::code source="snippets/custom-urls/AspireApp.AppHost/Program.WithUrlForEndpoint.cs" id="withurlforendpoint"::: | ||
|
|
||
| <!-- TODO: Add xref to ResourceUrlAnnotation when available --> | ||
|
|
||
| The preceding example assumes that the `api` project resource has an `https` endpoint configured. The `WithUrlForEndpoint` method updates the `ResourceUrlAnnotation` associated with the endpoint. In this case, it assigns the display text to `Scalar (HTTPS)` and appends the `/scalar` path to the URL. | ||
|
|
||
| When the resource is started, the URL is available in the dashboard as shown in the following screenshot: | ||
|
|
||
| :::image type="content" source="dashboard/media/custom-urls/custom-url-scalar-https.png" alt-text=".NET Aspire dashboard with custom Scalar URL." lightbox="dashboard/media/custom-urls/custom-url-scalar-https.png"::: | ||
|
|
||
| ### Customize multiple resource URLs | ||
|
|
||
| <!-- TODO: Add xref to WithUrls when available --> | ||
|
|
||
| To customize multiple URLs for a resource, use the `WithUrls` method. This method allows you to specify multiple URLs for a resource, each with its own display text. The following example demonstrates how to set multiple URLs for a project resource: | ||
|
|
||
| :::code source="snippets/custom-urls/AspireApp.AppHost/Program.WithUrls.cs" id="withurls"::: | ||
|
|
||
| The preceding code iterates through the URLs defined for the `api` project resource and assigns a display text and order to each URL. The resulting URLs are available in the dashboard as shown in the following screenshot: | ||
|
|
||
| :::image type="content" source="dashboard/media/custom-urls/custom-url-ordered.png" alt-text=".NET Aspire dashboard custom ordered and named URLs."::: | ||
|
|
||
| ## URL customization lifecycle | ||
|
|
||
| URL customization callbacks run during the application model lifecycle, specifically during the <xref:Aspire.Hosting.ApplicationModel.BeforeResourceStartedEvent> event processing. URLs associated with endpoints become active and appear on the dashboard once the endpoint itself becomes active. URLs not associated with endpoints become active only when the resource enters the "Running" state. This ensures that all custom URLs are accurately represented and available when the application resources are fully operational. | ||
|
|
||
| ## See also | ||
|
|
||
| - [.NET Aspire dashboard overview](./overview.md) | ||
| - [.NET Aspire app host](../app-host.md) | ||
Binary file added
BIN
+38.2 KB
docs/fundamentals/dashboard/media/custom-urls/custom-url-admin-portal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+36.2 KB
docs/fundamentals/dashboard/media/custom-urls/custom-url-scalar-https.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions
14
docs/fundamentals/snippets/custom-urls/AspireApp.Api/AspireApp.Api.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.3" /> | ||
| <PackageReference Include="Scalar.AspNetCore" Version="2.1.7" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
6 changes: 6 additions & 0 deletions
6
docs/fundamentals/snippets/custom-urls/AspireApp.Api/AspireApp.Api.http
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| @AspireApp.Api_HostAddress = http://localhost:5020 | ||
|
|
||
| GET {{AspireApp.Api_HostAddress}}/weatherforecast/ | ||
| Accept: application/json | ||
|
|
||
| ### |
30 changes: 30 additions & 0 deletions
30
docs/fundamentals/snippets/custom-urls/AspireApp.Api/AspireApp.Api.sln
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 17 | ||
| VisualStudioVersion = 17.14.35906.104 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireApp.Api", "AspireApp.Api.csproj", "{BB5FD48A-DA3C-4E2C-B01B-FF8FB922F4F5}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireApp.AppHost", "..\AspireApp.AppHost\AspireApp.AppHost.csproj", "{DC5D0ECC-8CBC-4436-B1DC-3D2681DD4B50}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {BB5FD48A-DA3C-4E2C-B01B-FF8FB922F4F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {BB5FD48A-DA3C-4E2C-B01B-FF8FB922F4F5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {BB5FD48A-DA3C-4E2C-B01B-FF8FB922F4F5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {BB5FD48A-DA3C-4E2C-B01B-FF8FB922F4F5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {DC5D0ECC-8CBC-4436-B1DC-3D2681DD4B50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {DC5D0ECC-8CBC-4436-B1DC-3D2681DD4B50}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {DC5D0ECC-8CBC-4436-B1DC-3D2681DD4B50}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {DC5D0ECC-8CBC-4436-B1DC-3D2681DD4B50}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {6D149486-7C78-4537-B183-314816378E9C} | ||
| EndGlobalSection | ||
| EndGlobal |
120 changes: 120 additions & 0 deletions
120
docs/fundamentals/snippets/custom-urls/AspireApp.Api/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| using Scalar.AspNetCore; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| // Add services to the container. | ||
| // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi | ||
| builder.Services.AddOpenApi(); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| // Configure the HTTP request pipeline. | ||
| if (app.Environment.IsDevelopment()) | ||
| { | ||
| app.MapOpenApi(); | ||
| app.MapScalarApiReference(); | ||
| } | ||
|
|
||
| app.UseHttpsRedirection(); | ||
|
|
||
| var summaries = new[] | ||
| { | ||
| "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
| }; | ||
|
|
||
| app.MapGet("/weatherforecast", () => | ||
| { | ||
| var forecast = Enumerable.Range(1, 5).Select(index => | ||
| new WeatherForecast | ||
| ( | ||
| DateOnly.FromDateTime(DateTime.Now.AddDays(index)), | ||
| Random.Shared.Next(-20, 55), | ||
| summaries[Random.Shared.Next(summaries.Length)] | ||
| )) | ||
| .ToArray(); | ||
| return forecast; | ||
| }) | ||
| .WithName("GetWeatherForecast"); | ||
|
|
||
| app.MapGet("/admin", () => | ||
| { | ||
| return Results.Content(""" | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Admin Portal Login</title> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| </head> | ||
| <body style=" | ||
| margin: 0; | ||
| padding: 0; | ||
| box-sizing: border-box; | ||
| font-family: 'Segoe UI', sans-serif; | ||
| background: linear-gradient(to right, #667eea, #764ba2); | ||
| height: 100vh; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| "> | ||
|
|
||
| <div style=" | ||
| background-color: white; | ||
| padding: 2rem; | ||
| border-radius: 12px; | ||
| box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1); | ||
| width: 100%; | ||
| max-width: 400px; | ||
| "> | ||
| <h2 style=" | ||
| margin-bottom: 1.5rem; | ||
| text-align: center; | ||
| color: #333; | ||
| ">Admin Portal</h2> | ||
|
|
||
| <form> | ||
| <label for="email" style="display: block; margin-bottom: 0.5rem; color: #555;">Email</label> | ||
| <input type="email" id="email" name="email" placeholder="[email protected]" style=" | ||
| width: 100%; | ||
| padding: 0.75rem; | ||
| margin-bottom: 1rem; | ||
| border: 1px solid #ccc; | ||
| border-radius: 8px; | ||
| font-size: 1rem; | ||
| " required> | ||
|
|
||
| <label for="password" style="display: block; margin-bottom: 0.5rem; color: #555;">Password</label> | ||
| <input type="password" id="password" name="password" placeholder="••••••••" style=" | ||
| width: 100%; | ||
| padding: 0.75rem; | ||
| margin-bottom: 1.5rem; | ||
| border: 1px solid #ccc; | ||
| border-radius: 8px; | ||
| font-size: 1rem; | ||
| " required> | ||
|
|
||
| <button type="submit" style=" | ||
| width: 100%; | ||
| padding: 0.75rem; | ||
| background-color: #667eea; | ||
| color: white; | ||
| border: none; | ||
| border-radius: 8px; | ||
| font-size: 1rem; | ||
| cursor: pointer; | ||
| transition: background-color 0.3s ease; | ||
| ">Login</button> | ||
| </form> | ||
| </div> | ||
|
|
||
| </body> | ||
| </html> | ||
| """, "text/html"); | ||
| }); | ||
|
|
||
| app.Run(); | ||
|
|
||
| internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) | ||
| { | ||
| public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
| } |
23 changes: 23 additions & 0 deletions
23
docs/fundamentals/snippets/custom-urls/AspireApp.Api/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "http://localhost:5020", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "https://localhost:7233;http://localhost:5020", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
docs/fundamentals/snippets/custom-urls/AspireApp.Api/appsettings.Development.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
docs/fundamentals/snippets/custom-urls/AspireApp.Api/appsettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
21 changes: 21 additions & 0 deletions
21
docs/fundamentals/snippets/custom-urls/AspireApp.AppHost/AspireApp.AppHost.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Sdk Name="Aspire.AppHost.Sdk" Version="9.2.0-preview.1.25208.5" /> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <UserSecretsId>31d1f6cf-dfb5-4923-b92a-6c0e9e032f15</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.AppHost" Version="9.2.0-preview.1.25208.5" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\AspireApp.Api\AspireApp.Api.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
15 changes: 15 additions & 0 deletions
15
docs/fundamentals/snippets/custom-urls/AspireApp.AppHost/Program.WithUrl.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| internal static partial class Program | ||
| { | ||
| internal static void WithUrlExample(string[] args) | ||
| { | ||
| // <withurl> | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var api = builder.AddProject<Projects.AspireApp_Api>("api"); | ||
|
|
||
| api.WithUrl($"{api.GetEndpoint("https")}/admin"), "Admin Portal"); | ||
|
|
||
| builder.Build().Run(); | ||
| // </withurl> | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
docs/fundamentals/snippets/custom-urls/AspireApp.AppHost/Program.WithUrlForEndpoint.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| internal static partial class Program | ||
| { | ||
| internal static void WithUrlForEndpointExample(string[] args) | ||
| { | ||
| // <withurlforendpoint> | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| builder.AddProject<Projects.AspireApp_Api>("api") | ||
| .WithUrlForEndpoint("https", url => | ||
| { | ||
| url.DisplayText = "Scalar (HTTPS)"; | ||
| url.Url += "/scalar"; | ||
| }); | ||
|
|
||
| builder.Build().Run(); | ||
| // </withurlforendpoint> | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
docs/fundamentals/snippets/custom-urls/AspireApp.AppHost/Program.WithUrls.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| internal static partial class Program | ||
| { | ||
| internal static void WithUrlsExample(string[] args) | ||
| { | ||
| // <withurls> | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| builder.AddProject<Projects.AspireApp_Api>("api") | ||
| .WithUrls(context => | ||
| { | ||
| foreach (var tuple in context.Urls | ||
| .Select(url => (Url: url, Uri: new Uri(url.Url))) | ||
| .OrderByDescending(_ => _.Uri.Scheme is "https") | ||
| .Select((pair, index) => (pair.Url, pair.Uri.Scheme, Index: index))) | ||
| { | ||
| var (url, scheme, index) = tuple; | ||
|
|
||
| // Order HTTPS first. | ||
| var order = context.Urls.Count - 1 - index; | ||
|
|
||
| url.DisplayText = $"{index + 1}. {scheme.ToUpper()}"; | ||
| url.DisplayOrder = order; | ||
| } | ||
| }); | ||
|
|
||
| builder.Build().Run(); | ||
| // </withurls> | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
docs/fundamentals/snippets/custom-urls/AspireApp.AppHost/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Uncomment a single line to run the example | ||
|
|
||
| // Admin Portal | ||
| WithUrlExample(args); | ||
|
|
||
| // Ordered / Schemes | ||
| //WithUrlsExample(args); | ||
|
|
||
| // Scalar (HTTPS) | ||
| //WithUrlForEndpointExample(args); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.