Skip to content

.NET 9 - Blazor Web App - Global Server Rendering with Individual Accounts not working #58967

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

Closed
1 task done
ekomsctr opened this issue Nov 14, 2024 · 4 comments
Closed
1 task done
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved

Comments

@ekomsctr
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Just created a brand new Blazor Web App (Global Server Render Mode) project, but i found that both the Login and Register page (in general every page that uses Identity) does not work correctly as there is no User after the login.

Only if i do a full page refresh, then the authentication wires up and starts working again.

Expected Behavior

The NavigationManager correctly works as the current RenderMode is set to null in the App.razor

Steps To Reproduce

Spin un a brand new Blazor Web App with the following project creation settings:
Image

And you will get this exception right after the login (or registration), when the IdentityRedirectManager tries to redirect you to the next page (IdentityRedirectManager.cs:31)
Image

Exceptions (if any)

Microsoft.AspNetCore.Components.NavigationException
HResult=0x80131500
Message=Exception of type 'Microsoft.AspNetCore.Components.NavigationException' was thrown.
Source=Microsoft.AspNetCore.Components.Server
StackTrace:
at Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager.NavigateToCore(String uri, NavigationOptions options)
at Microsoft.AspNetCore.Components.NavigationManager.NavigateToCore(String uri, Boolean forceLoad)
at Microsoft.AspNetCore.Components.NavigationManager.NavigateTo(String uri, Boolean forceLoad, Boolean replace)
at TestAuth.Components.Account.IdentityRedirectManager.RedirectTo(String uri) in C:\my\work\cdesign\repo\HyperionNext\TestAuth\Components\Account\IdentityRedirectManager.cs:line 31
at TestAuth.Components.Account.IdentityRedirectManager.RedirectTo(String uri, Dictionary`2 queryParameters) in C:\my\work\cdesign\repo\HyperionNext\TestAuth\Components\Account\IdentityRedirectManager.cs:line 40
at TestAuth.Components.Account.Pages.Register.d__12.MoveNext() in C:\my\work\cdesign\repo\HyperionNext\TestAuth\Components\Account\Pages\Register.razor:line 96
at Microsoft.AspNetCore.Components.ComponentBase.d__30.MoveNext()

.NET Version

9.0.100

Anything else?

Visual Studio 2022 17.12.0

Host:
Version: 9.0.0
Architecture: x64
Commit: 9d5a6a9aa4

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Nov 14, 2024
@javiercn
Copy link
Member

@ekomsctr thanks for contacting us.

That exception is thrown and caught by the framework internally during prerendering to handle redirects. You can configure the debugger to avoid breaking on it.

@halter73 do you know why the debugger still breaks in this case? 

@javiercn
Copy link
Member

Dupe of #53996

@javiercn javiercn closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2024
@javiercn javiercn added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Nov 15, 2024
@ekomsctr
Copy link
Author

Hi, sorry for the late reply. I even tried to ignore the NavigationException as suggested in other issues, but still cannot get it to work. My problem, as opposed to others, it's that even if i catch the exception, no redirection is done.

Then, if i refresh manually the page, of course the authentication did work and everything works as expected.

If you need any indication or code, let me know i will try to make a small sample.

@darthdaniel85
Copy link

Hi @ekomsctr,
If you ignored the NavigationException it should work as long as the Redirect isn't used within any try-catch.
If you need to use a try-catch (I do) then try this (it should work): catch (Exception e) when (e is not NavigationException).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants