Skip to content

Can't add external service reference with base path other than "/" #13025

@sliekens

Description

@sliekens

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The URL validation for AddExternalService requires that the absolute path is "/"

This prevents the use of reverse proxies that route requests based on path segment like https://my-proxy/my-service-name/

Expected Behavior

Loosen the validation to expect that the path only ends with "/".

Steps To Reproduce

var builder = DistributedApplication.CreateBuilder(args);
builder.AddExternalService("myService", "https://my-proxy/my-service-name/");

or

var builder = DistributedApplication.CreateBuilder(args);
var myServiceUrl = builder.AddParameter("myServiceUrl", "https://my-proxy/my-service-name/");
builder.AddExternalService("myService", myServiceUrl);

Exceptions (if any)

Aspire.Hosting.DistributedApplicationException: The URL parameter 'myServiceUrl' for the external service 'myService' is invalid: The URI absolute path must be "/". (Parameter 'uri')
   at Aspire.Hosting.ResourceBuilderExtensions.<>c__DisplayClass24_0`1.<<WithReference>b__0>d.MoveNext() in /_/src/Aspire.Hosting/ResourceBuilderExtensions.cs:line 551
--- End of stack trace from previous location ---
   at Aspire.Hosting.ApplicationModel.ResourceExtensions.ProcessEnvironmentVariableValuesAsync(IResource resource, DistributedApplicationExecutionContext executionContext, Action`4 processValue, ILogger logger, String containerHostName, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs:line 352
   at Aspire.Hosting.Dcp.DcpExecutor.BuildEnvVarsAsync(ILogger resourceLogger, IResource modelResource, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/Dcp/DcpExecutor.cs:line 1974
   at Aspire.Hosting.Dcp.DcpExecutor.CreateExecutableAsync(AppResource er, ILogger resourceLogger, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/Dcp/DcpExecutor.cs:line 1255
   at Aspire.Hosting.Dcp.DcpExecutor.<>c__DisplayClass71_0.<<CreateSnapshotableResourcesAsync>g__CreateResourceExecutablesAsyncCore|0>d.MoveNext() in /_/src/Aspire.Hosting/Dcp/DcpExecutor.cs:line 1155

.NET Version info

.NET SDK:
 Version:           8.0.412
 Commit:            819e1a9566
 Workload version:  8.0.400-manifests.9cf71931
 MSBuild version:   17.11.31+933b72e36

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  24.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/8.0.412/

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.

Host:
  Version:      10.0.0
  Architecture: x64
  Commit:       b0f34d51fc

.NET SDKs installed:
  8.0.412 [/usr/share/dotnet/sdk]
  10.0.100 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.18 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.18 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_BUNDLE_EXTRACT_BASE_DIR           [/home/stelie/.cache/dotnet_bundle_extract]
  DOTNET_ROOT                              [/usr/share/dotnet]

global.json file:
  /home/stelie/src/dsp-thirdpartycommunicationmanagement-datasharing/global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Anything else?

Validation happens in:

if (uri.AbsolutePath != "/")
{
return new ArgumentException("The URI absolute path must be \"/\".", nameof(uri));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions