I am migrating a .NET 4.8 webforms app to a .NET 8.0 Blazor server application using YARP to handle routing requests between the webforms and Blazor app. I have run into a routing issue that I am quite confused by.
First here is my Blazor appsettings.json
configuration settings for the Reverse Proxy ...
"RemoteAppApiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX","ReverseProxy": {"Routes": {"fallbackRoute": {"ClusterId": "fallbackCluster","Order": 1,"Match": {"Path": "{**catch-all}" } } },"Clusters": {"fallbackCluster": {"Destinations": {"fallbackApp": {"Address": "https://localhost:####" } } } }}
This all works just fine except for loading the /_framework/blazor.server.js
script. This results in a 500 error in the Dev Tools console. When I look at the Blazor / .NET 8 console I am presented with the following:
2025-05-06 09:09:51 [DBG] 3 candidate(s) found for the request path '/_framework/blazor.server.js'{EventId={Id=1001, Name="CandidatesFound"}, SourceContext="Microsoft.AspNetCore.Routing.Matching.DfaMatcher", RequestId="0HNCCJT2CU2KU:0000000D", RequestPath="/_framework/blazor.server.js", ConnectionId="0HNCCJT2CU2KU"}2025-05-06 09:09:51 [DBG] Endpoint 'Blazor static files' with route pattern '/_framework/blazor.server.js' is valid for the request path '/_framework/blazor.server.js'{EventId={Id=1005, Name="CandidateValid"}, SourceContext="Microsoft.AspNetCore.Routing.Matching.DfaMatcher", RequestId="0HNCCJT2CU2KU:0000000D", RequestPath="/_framework/blazor.server.js", ConnectionId="0HNCCJT2CU2KU"}2025-05-06 09:09:51 [DBG] Endpoint 'null' with route pattern '/_framework/blazor.server.js' is valid for the request path '/_framework/blazor.server.js'{EventId={Id=1005, Name="CandidateValid"}, SourceContext="Microsoft.AspNetCore.Routing.Matching.DfaMatcher", RequestId="0HNCCJT2CU2KU:0000000D", RequestPath="/_framework/blazor.server.js", ConnectionId="0HNCCJT2CU2KU"}2025-05-06 09:09:51 [DBG] Endpoint 'fallbackRoute' with route pattern '{**catch-all}' is valid for the request path '/_framework/blazor.server.js'{EventId={Id=1005, Name="CandidateValid"}, SourceContext="Microsoft.AspNetCore.Routing.Matching.DfaMatcher", RequestId="0HNCCJT2CU2KU:0000000D", RequestPath="/_framework/blazor.server.js", ConnectionId="0HNCCJT2CU2KU"}2025-05-06 09:09:51 [ERR] An unhandled exception has occurred while executing the request.{EventId={Id=1, Name="UnhandledException"}, SourceContext="Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware", RequestId="0HNCCJT2CU2KU:0000000D", RequestPath="/_framework/blazor.server.js", ConnectionId="0HNCCJT2CU2KU"}Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches:Blazor static filesfallbackRoute at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(Span`1 candidateState) at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ProcessFinalCandidates(HttpContext httpContext, Span`1 candidateState) at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.Select(HttpContext httpContext, Span`1 candidateState) at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.MatchAsync(HttpContext httpContext) at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.TryServeStaticFile(HttpContext context, String contentType, PathString subPath) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
I understand the message. I have 3 valid endpoints and it doesn't know which one it should use. What I do not understand is since I have only defined one endpoint, where the 'Blazor Static Files' and "null" endpoints are being defined. I have actually tried excluding requests starting with /_Framework
in the appsettings ... from the acceptable candidates ...
"RemoteAppApiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX","ReverseProxy": {"Routes": {"fallbackRoute": {"ClusterId": "fallbackCluster","Order": 1,"Match": {"Path": "{notFramework:regex(^(?!_framework).+$)}/{**catch-all}" } },"rootRoute": {"ClusterId": "fallbackCluster","Order": 2,"Match": {"Path": "/" } } },"Clusters": {"fallbackCluster": {"Destinations": {"fallbackApp": {"Address": "https://localhost:44363" } } } }}
But this still leaves me with the 'null and 'Blazor Static Files' routes creating conflict.
Any thoughts? Is there something in the webforms (client) application to look at? This didn't feel like a client thing as it appears to deal with routing. My client side webforms only sets up the web adapters (I know this code is a bit broken up syntactically but that was to ease debugging).
Private Sub ConfigureBlazorSessionSharing() Dim webAdapterBuilder = SystemWebAdapterConfiguration.AddSystemWebAdapters(Me) webAdapterBuilder.AddProxySupport(Function(options) options.UseForwardedHeaders = True End Function) webAdapterBuilder.AddSessionSerializer(Function(options) options.ThrowOnUnknownSessionKey = False End Function) webAdapterBuilder.AddJsonSessionSerializer(Function(options) options.RegisterKey(Of String)("test-value") options.RegisterKey(Of Int32)("UserPK") options.RegisterKey(Of String)("UserID") options.RegisterKey(Of String)("username") options.RegisterKey(Of Boolean)("Reset")'options.RegisterKey(Of CAuser)("UserObj") End Function) webAdapterBuilder.AddSessionSerializer(Function(options) options.ThrowOnUnknownSessionKey = True End Function) Dim remoteServerBuilder = webAdapterBuilder.AddRemoteAppServer(Function(options) options.ApiKey = ConfigurationManager.AppSettings("RemoteAppApiKey") End Function) remoteServerBuilder.AddSessionServer() remoteServerBuilder.AddAuthenticationServer()End Sub
I have found these (and other) forums to be a little soft on YARP assistance so hopefully this strikes a chord and someone can shed some light on this. I have been looking at this for days and am at a real dead end.
Thanks in advance.