Search code examples
c#asp.net-corevisual-studio-2019blazor-webassembly

Wrong redirect when login in blazor application


I use ASP.NET Core 3.1 Blazor webassembly application (the default one created by Visual Studio 2019).

I hooked up ASP.NET Identity for user management, added scaffolded Identity item (login, registration etc)

When I click Register, the application correctly redirects to

https://localhost:44349/Identity/Account/Register

but if I click Login, the application redirects to

https://localhost:44349/Account/Login

which is wrong (I expect https://localhost:44349/Identity/Account/Login)

LoginDisplay.razor:

<AuthorizeView>
    <Authorized>
        <a href="authentication/profile">Hello, @context.User.Identity.Name!</a>
        <button class="nav-link btn btn-link" @onclick="BeginSignOut">Log out</button>
    </Authorized>
    <NotAuthorized>
        <a href="authentication/register">Register</a>
        <a href="authentication/login">Log in</a>
    </NotAuthorized>
</AuthorizeView>

What did I miss?


Solution

  • by replacing

    services.AddIdentity<ApplicationUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultTokenProviders();
    

    with

    services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultTokenProviders();
    

    I resolved the issue