dotnet / dotnet/aspnetcore

WebApplication.UseStatusCodePages() cannot handle unauthorized requests without explicit UseAuthorization() call

Open
#49,515 7 comments 1 reaction 0 assignees View on GitHub
area-hosting area-middleware
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

These are observations from implementing auth with Server-side rendered pages (SSR) in Blazor Preview 6 - using Razor components instead of MVC Razor pages.

Cookie auth just works, that is great. But there are some issues:

Issues:

- ``AuthorizeRouteView`` doesn't work with the router. The ``NotAuthorized`` fragment does not get rendered. Instead I get redirected to a layout-less page saying: ``Error: 401 Unauthorized``.

- The ``LoginDisplay`` doesn't re-ender when logged in using form. Redirecting to another page would help here.

Questions:
- How do I redirect to another URL from a component that server render? ``NavigationManager`` of course doesn't work here.

My github repo (branch): https://github.com/marinasundstrom/Blazor8Test/tree/auth

### Expected Behavior

When unauthorized and entering page that requires authorization,
I expect the ``NotAuthorized`` fragment to be rendered with the ``MainLayout``.

### Steps To Reproduce

https://github.com/marinasundstrom/Blazor8Test/tree/auth

### Exceptions (if any)

_No response_

### .NET Version

8.0.100-preview.6.23330.14

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.