.NET CORE not picking up Partial - The default Identity UI layout requires a partial view

Viewed 727

I am following this tutorial here to add Authentication to my blazor application

Unfortunately when I run the web app, the partial isn't being picked up and this is the error The default Identity UI layout requires a partial view '_LoginPartial' usually located at '/Pages/_LoginPartial' or at '/Views/Shared/_LoginPartial' to work. Based on your configuration we have looked at it in the following locations:

I tried moving the _LoginPartial.cshtml around but it didn't work. If I can get some assistance please on how to get my application to pick up the partial.

enter image description here

1 Answers

Based on the steps that you followed to configure Identity service within Blazor app, I can reproduce same issue as below.

To fix it, you can try to manually create and put _LoginPartial.cshtml file in following area structure.

enter image description here

Code of _LoginPartial.cshtml

@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager

<ul class="navbar-nav">
    @if (SignInManager.IsSignedIn(User))
    {
        <li class="nav-item">
            <a class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Manage/Index" title="Manage">Hello @User.Identity.Name!</a>
        </li>
        <li class="nav-item">
            <form class="form-inline" asp-area="Identity" asp-page="/Account/Logout">
                <button type="submit" class="nav-link btn btn-link text-dark">Logout</button>
            </form>
        </li>
    }
    else
    {
        <li class="nav-item">
            <a class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Register">Register</a>
        </li>
        <li class="nav-item">
            <a class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Login">Login</a>
        </li>
    }
</ul>

Exception

enter image description here

Login successfully

enter image description here

Related