I have an asp net core solution with identity which I thought I had removed the section of code that included these login page links: Forgot Password, Register as a New User, Resend Email Confirmation and Use Another Service to Login (text & link) But this content is displayed and I can’t figure out why?
I have ‘marked’ the last line of ~repoViewsShared_LoginPartial.cshtml
The code:
@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">Kia Ora/Welcome @User.Identity.Name</a>
</li>
<li class="nav-item">
<form class="form-inline" asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Action("Index", "Home", new { area = "" })">
<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/Login"></a>
</li>
}
<!-- LoginPartial.cshtml file ends here-->
</ul>
When I launch the app using localhost, the login page has all the links, as though I never removed them. This can be seen looking at the page using Developer Tools (right-click image "Open image in new tab"
There are other repo folders, in the parent folder, with different versions. But I have been careful to open this folder in Visual Studio and double click on solutions file. There are no resources outside of this folder. How can this happen?
I believe the bootstrap container code and the HTML role attribute don’t give any clues. I could be wrong.
2
Answers
The question stated a presumption that Microsoft Web App default registration details etc had been removed from the solution. This is what I required and this proved to be correct. The original method I used, believing to be the best, was to scaffold all identity elements (all boxes ticked on Add Identity page of scaffolding) and then edit/remove what I didn't need. The only editing I needed to do was to remove the items in the question from
~AreasIdentityPagesAccountLogin.cshtml
I believe the above file is linked via the file
~ViewsShared_LoginPartial.cshtml
to provide a 'clean' login page (without registration details) This can be seen in the code section of the question.The issues were:
~AreasIdentityPagesAccount
had been temporarily excluded from the project.I still don't understand how all the files in Account & Management folders can be excluded from the project resulting in the default login page. A manual check of all my code files would suggest this is not possible.
For anyone looking for information on scaffolding identity. I found the following useful.
Introduction to Identity on ASP.NET Core
Where are the Login and Register pages in an AspNet Core scaffolded app?
I think you are getting a bit cross-eyed looking for things, that are magically there, if you don’t know where to look.
The code you are showing us is the LoginPartial view, that is injected into your Navbar. If you haven’t changed it, that should be in
_Layout.cshtml
:What you are showing us as a screenshot is the Login view, which … is not there. Asp.net core automatically adds them behind the scenes as a default implementation. You can of course override them.
Once the process has finished, those scaffolded items should be inside your
/Areas/Identity
folder.Reference: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-7.0&tabs=visual-studio