NavigateTo within OnInitialized not working #28355
Labels
area-blazor
Includes: Blazor, Razor Components
✔️ Resolution: Answered
Resolved because the question asked by the original author has been answered.
question
Status: Resolved
Describe the bug
Following the advice give here, I added RedirectToLogin.razor in my Blazor Server Side App. Unfortunately,
NavigateTo
throws an exception when placed insideOnInitialized
. It is a known problem and e. g. in this SO question it is recommended to place it inOnAfterRender
or disable server prerendering. The SO question also referrs to issues (#11591 and #13582) which are marked as closed, but the problem still exists.To Reproduce
Use this git repository which is a Blazor Server Side App with Identity and the RedirectToLogin and the access-protected Counter page. Start the app and add '/counter' to the URL (clicking the 'Counter' menu item does not show the same exception) which will call ´RedirectToLogin´ and throw the exception.
Please note, that ´NavigateTo´ works despite throwing the exception.
Exceptions (if any)
With '/counter' in the URL: 'Microsoft.AspNetCore.Components.NavigationException' in Microsoft.AspNetCore.Components.dll
With the 'Counter' button: 'System.Threading.Tasks.TaskCanceledException' in System.Private.CoreLib.dll (might not be related to my question, but is still interesting that an exception is thrown)
Further technical details
dotnet --info
Microsoft Visual Studio Enterprise 2019, 16.8.2
The text was updated successfully, but these errors were encountered: