ASP.NET MVC Core default layout page not loading if I navigate to any razor page in Identity area e.g login, register etc

sama clif 5 Reputation points
2023-05-04T07:41:45.3766667+00:00

I am currently working on an ** MVC Core project using .Net8 preview**. Everything on the project works fine except the pages included after scaffolding identity. i.e Login, Register etc. When I navigate to login\Register page for example, the default layout of my app doesn't load. Meaning my navbar and footer is not displayed. Instead a blank navbar is displayed with nothing but the project name and Login/Register button at top. But on all the razor views everything works find.

What I have also noticed is that if I try to edit the Login.cshtml page, the changes doesn't reflect on the UI. (Not related to HotReload). Even if I clean, rebuild or restart visual studio, the changes don't reflect when login page is loaded. For example I modified this simple h2 on login.cshtml

From

<h2>Use223 a local account to log in.</h2>

To

<h2>Use223 a local account to log in.</h2>

Nothing happens. I don't know if the Account pages are being loaded from another location other than the folders in my project.

I have tried scaffolding identity several times from several previous versions of the project, and end up with same issue.

I have mapped razor pages in Program.cs file _ I have correctly specify the layout page in ViewStart file inside Accounts folder. I just deleted the entire Identity folder inside areas. but the login page still loads

@{ Layout = "~/Views/Shared/_Layout.cshtml"; }

Microsoft Identity Manager
Microsoft Identity Manager
A family of Microsoft products that manage a user's digital identity using identity synchronization, certificate management, and user provisioning.
707 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,921 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,612 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,507 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,012 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,706 Reputation points
    2023-05-05T15:17:07.6833333+00:00

    Razor pages do not use the same layout pages as mvc views. The identity pages and layouts are built into the identity package. You need to override the default razor pages.

    See layout section of scaffolding

    https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-7.0&tabs=visual-studio


  2. sama clif 5 Reputation points
    2023-05-08T04:11:51.03+00:00

    Finally resolved the issue. Turns out that the version of .Net 8 preview

    I have installed requires at least visual studio 2022 17.6 preview 2. I was using vs 2022 17.5.5. After upgrading to 17.6 preview 6, the issue went away and scaffolding identity works perfectly now.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.