-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Blazor has case sensitive URLs when hosted in a Child Directory #6818
Comments
* Add event names for logs (dotnet#6818)
Temporary fix: Put this in the index.html, above the blazor script tag:
|
Still seeing this in 3.1 preview client side blazor app. |
Same issue for us with a client size WASM hosted using Core. MapFallbackToFile has a path (we have the app in a child directory) and that path has to match including case of the base href in index.html or we get the error Rick mentioned. Please fix - we can't control how others link to our app, only our own links. |
Still see this in Blazor WASM .NET 5, WebAssembly 5.0.2 blazor.webassembly.js:1 System.ArgumentException: The URI 'https://localhost:44302/firstapp' is not contained by the base URI 'https://localhost:44302/FirstApp/'. |
This is not a bug. Map is case sensitive, see here If you want it to be case insensitive you can use map.MapWhen(c => c.Request.Path.StartsWithSegments("firstapp", StringComparison.OrdinalIgnoreCase),
child => child.UseServerSideBlazor(....); |
Thanks for contacting us. We're moving this issue to the |
" or it's very rare and low-impact issue, we will close it " Oh well |
Thanks for contacting us. We're moving this issue to the |
We should celebrate the 4 year anniversary of this arguably breaking bug in a ~ a month! 🥳 I sympathize with Sam, I almost sold people on Blazor. |
Had a quick discussion with the team about this one and we will consider adding an option to opt-in into the desired behavior (keeping the current behavior as default). |
Having it as an option would be great. |
this is quite high impact for us, because having a lot of people within the company everyone types urls differently, this is especially bad when people type in the url incorrectly the first time, browser caches it in history, and it will never work for the user unless he goes through other URL or clears browser history.... |
Hi team. |
Hello team, This is also an issue that keeps getting pushed. We need it also :( Thanks, |
My team is experiencing this as well with a couple new websites we are developing using Blazor. We are still a ways out from either being ready to go to production but we are very much hoping this will have a better resolution by then. |
Add in a setting to the {
"BASE_PATH": "/app"
} Add in a class that will programmatically set the base path in public class BlazorQualityControlService
{
IConfiguration Configuration;
IHttpContextAccessor HttpContextAccessor;
public BlazorQualityControlService(IHttpContextAccessor accessor, IConfiguration configuration)
{
HttpContextAccessor = accessor;
Configuration = configuration;
}
public string GetBasePath()
{
// If the base path was set, find it in the base URI.
if (Configuration["BASE_PATH"] != null)
{
// Find the part of the request URI that matches the base path using case insensitive matching.
string basePath = Configuration["BASE_PATH"] ?? "";
string requestPath = HttpContextAccessor.HttpContext?.Request.GetDisplayUrl() ?? "";
int index = requestPath.IndexOf(basePath, StringComparison.OrdinalIgnoreCase);
// Grab the case-sensitive base path from the request URI.
string qualityControlBasePath = basePath;
if (index >= 0)
{
qualityControlBasePath = requestPath.Substring(index, basePath.Length);
}
return qualityControlBasePath + "/";
}
else
{
return "/";
}
}
} Add in the service in your start up: builder.Services.AddTransient<BlazorQualityControlService>(); Update the @inject BlazorQualityControlService BlazorQualityControlService
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="@(BlazorQualityControlService.GetBasePath())" /> Additionally, I also have the following set: if (builder.Configuration["BASE_PATH"] != null)
{
app.UsePathBase(builder.Configuration["BASE_PATH"]);
}
I tested this with both setting a BASE_PATH and not setting a BASE_PATH and it seems to work for me. I hope this helps! |
Here's another workaround for those moving from blazor server to blazor web: public static class NavigationManagerExtensions
{
public static string GetBasePath(this NavigationManager navigationManager)
{
return new Uri(navigationManager.BaseUri).GetComponents(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.UriEscaped);
}
} @inject NavigationManager NavigationManager
<head>
<base href="@(NavigationManager.GetBasePath())" />
</head> |
And
This way is worked on .Net 8 But When I upgrade to .Net 9 Blazor.web.js is break. it can't relly to use blazor.web.js work |
@Edemilorhea I could be wrong, but the error does not seem related. |
(NOTE: this report is in the context of "server-side" Blazor app hosting)
It is possible to host Blazor in a child directory by:
app.Map("/dashboard", child => { child.UseServerSideBlazor<DiskBounty.Dashboard.Startup>(); });
and
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 ---
The text was updated successfully, but these errors were encountered: