Skip to content
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

When accessing a page with Authorize attribute set from Sidebar2 component, the behavior has different. #975

Open
masukatto0281 opened this issue Dec 11, 2024 · 0 comments

Comments

@masukatto0281
Copy link

Describe the bug
Accessing a page with the Authorize attribute set via the Sidebar2 component will display the Login page. (Not on Access denied page)

To Reproduce

  1. Create project "BlazorApp1".
  2. Project setting is set to ".NET 8.0 / Identity account / Not HTTPS / Interactive Server Rendering / Global Interactivity / Include sample pages".
  3. Follow Getting started for initial setup.
  4. Replace sample navbar to Sidebar2 component.
  5. Make Test.razor page. And write @attribute [Authorize(Roles = "AnyRole")].
  6. Debug project.
  7. Login any account. (Accounts that do not have the Role specified in attirubute)
  8. Access to /Test via Sidebar2 component.

Expected behavior
The login page appears even though you are already logged in.
Access denied page is displayed when accessed from navbar of sample or from a direct link (use browsers address bar).

Expect: http://localhost:5002/Account/AccessDenied?ReturnUrl=%2FTest
Actual: http://localhost:5002/Account/Login?returnUrl=http%3A%2F%2Flocalhost%3A5002%2FTest

Versions (please complete the following information):

  • .NET Version: .NET 8
  • BlazorBootstrap: 3.2.0
  • Blazor WebAssembly / Server: Server
  • Blazor Interactive Render Mode: Server
  • Blazor Interactivity Location: Global

Sample code

@*NavMenu.razor*@
@rendermode InteractiveServer
@inject AuthenticationStateProvider AuthState

<div class="bb-page">
    <Sidebar2 href="/" DataProvider="Sidebar2DataProvider"
              Title="BlazorApp1" BadgeText="v1.0" IconName="IconName.Bootstrap" />
</div>

@code {
    private IEnumerable<NavItem>? navItems;
    private async Task<Sidebar2DataProviderResult> Sidebar2DataProvider(Sidebar2DataProviderRequest request)
    {
        if (navItems is null)
            navItems = await GetNavItems();
        return await Task.FromResult(request.ApplyTo(navItems));
    }

    private async Task<IEnumerable<NavItem>> GetNavItems()
    {
        var items = new List<NavItem>
        {
            new NavItem { Id = "1", Href = "/", Text = "Home",  Match = NavLinkMatch.All },
            new NavItem { Id = "2", Href = "/counter", Text = "Counter",  Match = NavLinkMatch.All },
            new NavItem { Id = "3", Href = "/weather", Text = "Weather",  Match = NavLinkMatch.All },
            new NavItem { Id = "4", Href = "/auth", Text = "Auth Required",  Match = NavLinkMatch.All },
            new NavItem { Id = "5", Href = "/Account/Manage", Text = "Account",  Match = NavLinkMatch.All },
            new NavItem { Id = "6", Href = "/Test", Text = "Test",  Match = NavLinkMatch.All },
        };
        return items;
    }
}
@*Test.razor*@
@page "/Test"
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize(Roles = "Developer")]

<PageTitle>Test</PageTitle>

<div>
    test page.
</div>

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Edge
  • Version: 131
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant