Aspnetcore: Razor Components uri error in in .NET Core 3.0 Preview 4

Created on 23 Apr 2019  路  7Comments  路  Source: dotnet/aspnetcore

https://www.mydomain.com->nginx->http://localhost:5000 (http://www.mydomain.com)

[2019-04-23T19:13:27.624Z] Information: Normalizing '_blazor' to 'https://www.mydomain.com/_blazor'.
blazor.server.js:1 [2019-04-23T19:13:27.965Z] Information: WebSocket connected to wss://www.mydomain.com/_blazor?id=_GncinNaDXYxKd510uOuOA.
blazor.server.js:8 Uncaught (in promise) Error: System.ArgumentException: The URI 'https://www.mydomain.com/counter' is not contained by the base URI 'http://www.mydomain.com/'.
at Microsoft.AspNetCore.Components.UriHelperBase.ToBaseRelativePath(String baseUri, String locationAbsolute)
at Microsoft.AspNetCore.Components.Routing.Router.Refresh()
at Microsoft.AspNetCore.Components.Routing.Router.OnLocationChanged(Object sender, String newAbsoluteUri)
at Microsoft.AspNetCore.Components.UriHelperBase.TriggerOnLocationChanged()
at Microsoft.AspNetCore.Components.Server.Circuits.RemoteUriHelper.NotifyLocationChanged(String uriAbsolute)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.JSInterop.DotNetDispatcher.InvokeSynchronously(String assemblyName, String methodIdentifier, Object targetInstance, String argsJson)
at Microsoft.JSInterop.DotNetDispatcher.BeginInvoke(String callId, String assemblyName, String methodIdentifier, Int64 dotNetObjectId, String argsJson)
at endInvokeDotNetFromJS (https://www.mydomain.com/_framework/blazor.server.js:8:21783)
at https://www.mydomain.com/_framework/blazor.server.js:8:21434
at new Promise ()
at e.beginInvokeJSFromDotNet (https://www.mydomain.com/_framework/blazor.server.js:8:21403)
at https://www.mydomain.com/_framework/blazor.server.js:1:16653
at Array.forEach ()
at e.invokeClientMethod (https://www.mydomain.com/_framework/blazor.server.js:1:16624)
at e.processIncomingData (https://www.mydomain.com/_framework/blazor.server.js:1:14624)
at e.connection.onreceive (https://www.mydomain.com/_framework/blazor.server.js:1:11165)
at WebSocket.i.onmessage (https://www.mydomain.com/_framework/blazor.server.js:1:30454)

area-blazor bug help wanted

All 7 comments

Can you please post repro steps? Thanks.

I have the same problem.
it occurs when navigating on the website.

I'm hosting my Blazor-ServerSide application within a docker container. Behind a nginx reverse proxy.

Outside (internet): https - port 443
Internal (docker network / nginx <-> blazor-app): http - port 80

it looks like the application only detects it is localy running on port 80 (http) and do not accept the navigation url which is https (port 443) on the outside.

asp.net core versions i've tried:

  • 3.0.0-preview4-19216-03
  • 3.0.0-preview5-19225-01
Uncaught (in promise) Error: System.ArgumentException: The URI 'https://example.com/' is not contained by the base URI 'http://example.com/'.
   at Microsoft.AspNetCore.Components.UriHelperBase.ToBaseRelativePath(String baseUri, String locationAbsolute)
   at Microsoft.AspNetCore.Components.Routing.Router.Refresh()
   at Microsoft.AspNetCore.Components.Routing.Router.OnLocationChanged(Object sender, String newAbsoluteUri)
   at Microsoft.AspNetCore.Components.UriHelperBase.TriggerOnLocationChanged()
   at Microsoft.AspNetCore.Components.Server.Circuits.RemoteUriHelper.NotifyLocationChanged(String uriAbsolute)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.JSInterop.DotNetDispatcher.InvokeSynchronously(String assemblyName, String methodIdentifier, Object targetInstance, String argsJson)
   at Microsoft.JSInterop.DotNetDispatcher.BeginInvoke(String callId, String assemblyName, String methodIdentifier, Int64 dotNetObjectId, String argsJson)
    at endInvokeDotNetFromJS (https://example.com/_framework/blazor.server.js:8:21783)
    at https://example.com/_framework/blazor.server.js:8:21434
    at new Promise (<anonymous>)
    at e.beginInvokeJSFromDotNet (https://example.com/_framework/blazor.server.js:8:21403)
    at https://example.com/_framework/blazor.server.js:1:16653
    at Array.forEach (<anonymous>)
    at e.invokeClientMethod (https://example.com/_framework/blazor.server.js:1:16624)
    at e.processIncomingData (https://example.com/_framework/blazor.server.js:1:14624)
    at e.connection.onreceive (https://example.com/_framework/blazor.server.js:1:11165)
    at WebSocket.i.onmessage (https://example.com/_framework/blazor.server.js:1:30454)

I've found out that in my case the app.UseForwardedHeaders(); was missing. It got lost on merging, (my fault), after added it back to the middleware pipeline all worked as expected.

_Hint: Do not forget to configure it right:_
services.Configure<ForwardedHeadersOptions>(options => {options.ForwardedHeaders = ForwardedHeaders.All; //<-- On productive do set to the headers you need. options.KnownNetworks.Clear(); //<-- On productive do not clear, configure it with the right network options.KnownProxies.Clear(); //<-- On productive do not clear, configure it with the right proxies });

I have the same issue in our corporate cloud foundry instance (application running inside a docker image, the ssl offloading is done on a proxy running in front of the application).
With preivew-3, navigating was working without this issue.

Current error (with mcr.microsoft.com/dotnet/core-nightly/sdk:3.0 (preview-5-011568) docker image):

Uncaught (in promise) Error: System.ArgumentException: The URI 'https://example.com/icon' is not contained by the base URI 'http://example.com/'.
   at Microsoft.AspNetCore.Components.UriHelperBase.ToBaseRelativePath(String baseUri, String locationAbsolute)
   at Microsoft.AspNetCore.Components.Routing.Router.Refresh()
   at Microsoft.AspNetCore.Components.Routing.Router.OnLocationChanged(Object sender, String newAbsoluteUri)
   at Microsoft.AspNetCore.Components.UriHelperBase.TriggerOnLocationChanged()
   at Microsoft.AspNetCore.Components.Server.Circuits.RemoteUriHelper.NotifyLocationChanged(String uriAbsolute)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.JSInterop.DotNetDispatcher.InvokeSynchronously(String assemblyName, String methodIdentifier, Object targetInstance, String argsJson)
   at Microsoft.JSInterop.DotNetDispatcher.BeginInvoke(String callId, String assemblyName, String methodIdentifier, Int64 dotNetObjectId, String argsJson)
    at endInvokeDotNetFromJS (https://example.com/_framework/blazor.server.js:8:21783)
    at https://example.com/_framework/blazor.server.js:8:21434
    at new Promise (<anonymous>)
    at e.beginInvokeJSFromDotNet (https://example.swisscom.com/_framework/blazor.server.js:8:21403)
    at https://example.com/_framework/blazor.server.js:1:16653
    at Array.forEach (<anonymous>)
    at e.invokeClientMethod (https://example.com/_framework/blazor.server.js:1:16624)
    at e.processIncomingData (https://example.com/_framework/blazor.server.js:1:14624)
    at e.connection.onreceive (https://example.com/_framework/blazor.server.js:1:11165)
    at WebSocket.i.onmessage (https://example.com/_framework/blazor.server.js:1:30454)

Other workaround that worked for me (ssl offloading problem):

app.Use((ctx, next) =>
{
   ctx.Request.Scheme = "https";
   return next();
});

Set this as first middleware. Now the application think its running under https.

The work here is to add the forwarded headers middleware to the Blazor dev server.

I am experiencing a similar error with the nginx / blazor server side setup. I am proxying the external http://server:8080 to the locally running http://localhost:5000. The site loads fine, websocket connection is established and the page works.
However, on navigation it gives the same error as above, something like:
The URI http://server:8080/counter is not contained by the base URI http://server/
It seems that the base URI against which the navigation is checked does not take the port correctly into account

Thanks for contacting us. We're closing this issue as there was no community involvement here for quite a while now.

Was this page helpful?
0 / 5 - 0 ratings