使用Docker(https-portal)部署Blazor SSR页面路由时浏览器报错
Based on your description and troubleshooting steps so far, here are targeted suggestions to resolve the NotifyLocationChanged exception issue:
1. Fix ForwardedHeaders Configuration (Critical for Reverse Proxy Scenarios)
Your initial fix added the ForwardedHeadersOptions configuration, but you might be missing two key pieces that cause intermittent failures:
- Ensuring the middleware is enabled before routing in your
Configuremethod - Allowing the Docker proxy's IP to avoid being blocked by security restrictions
Update your Startup.cs like this:
// In ConfigureServices services.Configure<ForwardedHeadersOptions>(options => { options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; // Add your Docker gateway IP (usually 172.17.0.1; verify with `docker network inspect` if needed) options.KnownProxies.Add(IPAddress.Parse("172.17.0.1")); }); // In Configure (place this BEFORE UseRouting) app.UseForwardedHeaders(); app.UseRouting(); // Rest of your middleware setup...
Blazor Server relies on accurate protocol/host information to maintain circuit connections, so incomplete forwarded headers can break navigation after idle periods when circuits re-establish.
2. Enable Detailed Circuit Errors to Diagnose the Root Cause
Turn on detailed error logging for Blazor circuits to get the full exception stack trace—this will tell you exactly what's failing in NotifyLocationChanged:
// In ConfigureServices services.AddServerSideBlazor() .AddCircuitOptions(options => { options.DetailedErrors = true; });
Check your container logs or browser console again after enabling this; the detailed error will point to specific issues like invalid URL generation, missing dependencies, or circuit state corruption.
3. Audit Your Upgraded Project for Outdated Code/Assets
Since your project was upgraded from Preview 5 to 8, residual outdated components could be causing conflicts:
- NuGet Packages: Verify all
Microsoft.AspNetCore.*andMicrosoft.Extensions.*packages are at Preview 8 version in your.csprojfile—mixing versions is a common culprit. - Static Assets: Ensure
wwwroot/_framework/blazor.server.jsis the Preview 8 version. Old static files sometimes stick around after upgrades; rundotnet cleanand rebuild to refresh them. - Obsolete Startup Code: Remove any deprecated Blazor registration logic (e.g., old
AddBlazorvariants) or middleware that's no longer needed in Preview 8.
4. Validate Reverse Proxy WebSocket Handling
Even with WEBSOCKET: true set in https-portal, double-check that WebSocket traffic is being properly forwarded:
- Test accessing your app directly via
http://localhost:5000(bypass the proxy) to see if navigation works consistently. If it does, the issue is with your proxy's WebSocket configuration. - Inspect network traffic in your browser's dev tools to confirm the
Connection: UpgradeandUpgrade: websocketheaders are present during the WebSocket handshake—these are required for Blazor's circuit connections.
5. Rule Out Custom Circuit Logic
If your old project uses custom CircuitHandler implementations or circuit state management code, temporarily remove them to see if the error goes away. Preview versions of Blazor Server had breaking changes to circuit APIs between Preview 5 and 8, so custom logic might be incompatible.
Since your clean Preview 8 project works, the issue is almost certainly tied to leftover upgrade artifacts or incomplete proxy configuration in your existing codebase. Start with enabling detailed errors to get specific clues, then work through the other steps.
内容的提问来源于stack exchange,提问作者Gilian

