Aspnetcore: Blazor has case sensitive URLs when hosted in a Child Directory

Created on 17 Jan 2019  路  2Comments  路  Source: dotnet/aspnetcore

(NOTE: this report is in the context of "server-side" Blazor app hosting)

It is possible to host Blazor in a child directory by:

1) Adding an app.Map() in the Startup.Configure() method of the host:

app.Map("/dashboard", child => { child.UseServerSideBlazor(); });

and

2) Changing the base href in the index.html of the Blazor App:

base hef="/dashboard/"

However, if you do this you can only use the casing of the base href to access your Blazor pages. For example /dashboard/counter and /dashboard/Counter will work but /Dashboard/counter will not. That is you must always specify 'dashboard' (in this example) within the URL in lower case. This is a behavior difference to when the Blazor app is hosted in the root directory, where all urls are case _insensitive_.

The error you get is:

warn: Microsoft.AspNetCore.Blazor.Server.BlazorHub[0]
Unhandled Server-Side exception
System.AggregateException: One or more errors occurred. (Error: No element is currently associated with component 1) ---> Microsoft.AspNetCore.Blazor.Browser.Rendering.RemoteRendererException: Error: No element is currently associated with component 1
--- End of inner exception stack trace ---

affected-few area-blazor bug investigate severity-minor

Most helpful comment

Temporary fix: Put this in the index.html, above the blazor script tag:

<script>
    var path = window.location.pathname.split('/');
    var baseTag = document.getElementsByTagName('base');
    baseTag[0].setAttribute('href', '/' + path[1] + '/');
</script>

All 2 comments

Temporary fix: Put this in the index.html, above the blazor script tag:

<script>
    var path = window.location.pathname.split('/');
    var baseTag = document.getElementsByTagName('base');
    baseTag[0].setAttribute('href', '/' + path[1] + '/');
</script>

Still seeing this in 3.1 preview client side blazor app.
http://ringdev.com/Iosian4 works
http://ringdev.com/iosian4 does not, throws
blazor.webassembly.js:1 WASM: System.ArgumentException: The URI 'http://ringdev.com/iosian4' is not contained by the base URI 'http://ringdev.com/Iosian4/'.

Was this page helpful?
0 / 5 - 0 ratings