NavigationManager – Get current URL in a Blazor component

Use the Uri property from the NavigationManager class. How it works Get it from injection before using it on .razor pages: @inject NavigationManager MyNavigationManager Or like this in a .cs file if you prefer the “code-behind” experience: using Microsoft.AspNetCore.Components; // … [Inject] public NavigationManager MyNavigationManager {get; set;} = default!; Sample @page “/navigate” @inject NavigationManager MyNavigationManager … Read more

Display wait or spinner on API call

Option 1: Using Task.Delay(1) Use an async method. Use await Task.Delay(1) or await Task.Yield(); to flush changes private async Task AsyncLongFunc() // this is an async task { spinning=true; await Task.Delay(1); // flushing changes. The trick!! LongFunc(); // non-async code currentCount++; spinning=false; await Task.Delay(1); // changes are flushed again } Option 1 is a simple … Read more

Cannot debug Blazor wasm

I managed to get it working with Microsoft’s Edge browser. Although I’m using VSCode on linux, it should be similar for Visual Studio on Windows / Mac, because I believe the underlying Roslyn-based tooling is the same. Update dependencies Ensure you’re using the latest SDK version: 6.0.202. Check using dotnet –version. Install Edge Get the … Read more

How can I trigger/refresh my main .RAZOR page from all of its sub-components within that main .RAZOR page when an API call is complete?

The answer shows how to update the Blazor WeatherForecast application to demonstrate the state/notification pattern and how to use it in components. I’ve used the Weather Forecast application because there’s not enough detail in your question to use your code as the basis for an answer, and the Weather Forecast application provides a good template … Read more

How can one generate and save a file client side using Blazor?

Creator of Blazor Steve Sanderson used JavaScript interop for similar task during one of his last presentations. You can find example on BlazorExcelSpreadsheet Solution includes three parts: 1) JavaScript function saveAsFile(filename, bytesBase64) { var link = document.createElement(‘a’); link.download = filename; link.href = “https://stackoverflow.com/questions/52683706/data:application/octet-stream;base64,” + bytesBase64; document.body.appendChild(link); // Needed for Firefox link.click(); document.body.removeChild(link); } 2) C# … Read more

How to add OpenIdConnect via IdentityServer4 to ASP.NET Core ServerSide Blazor web app?

Your code suffers from a couple of maladies… The main issue is that your code provides no authentication challenge request mechanism that enables redirection to an authenticating agent such as IdentityServer. This is only possible with HttpContext, which is not available in SignalR (Blazor Server App). To solve this issue we’ll add a couple of … Read more

Get current URL in a Blazor component

Use the Uri property from the NavigationManager class. How it works Get it from injection before using it on .razor pages: @inject NavigationManager MyNavigationManager Or like this in a .cs file if you prefer the “code-behind” experience: using Microsoft.AspNetCore.Components; // … [Inject] public NavigationManager MyNavigationManager {get; set;} = default!; Sample @page “/navigate” @inject NavigationManager MyNavigationManager … Read more