ASP.NET MVC Core Account pages not showing Default Layout, Changes to login.cshtml page not reflecting on UI when app is built

sama clif 0 Reputation points
2023-05-07T07:51:22.0066667+00:00

After scaffolding Identity in an MVC project (.NET 8 ), the default layout page of the application doesn't load when I click login button therefore the Navbar and footer is gone. Also, If i modify the login.cshtml file, the changes do not show when i build the app. The default login page is always loaded. Even if I add breakpoints to the constructs in page model of the identity pages ( loign, register), those breakpoints never hit when i click corresponding buttons. So the pages must definitely be loading from somewhere else

I've tried building a dummy project from scratch using .NET 6 and then scaffold identity but this issue persist. So I do not know if this a visual studio error ( am using vs 2022 v17.5.5).

Every razor view in the project works fine and display my default layout. Oh before anyone suggests, I've actually map razor pages and all. So the pages get's loaded, just not with the default layout. And any modification to the identity pages (cshtml) never reflect on the view.

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.
648 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,574 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,345 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,396 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.
10,574 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. VasimTamboli 4,770 Reputation points
    2023-05-07T10:40:10.2966667+00:00
    It sounds like the issue might be related to how the Identity pages are being rendered in the application. By default, the Identity pages are scaffolded to use their own layout file, which might be why the default layout file is not being loaded.
    
    To change this behavior, you can modify the _ViewStart.cshtml file in your application. This file specifies the default layout file that should be used for all views in the application.
    
    To use the default layout file for the Identity pages, you can add the following code to the _ViewStart.cshtml file:
    
    python
    Copy code
    @{
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    Make sure that the path to the layout file is correct based on your project structure.
    
    Regarding the changes made to the login.cshtml file not reflecting on the UI when the app is built, this could be due to caching. Try clearing your browser cache or building the application with the "Clean Solution" option selected to ensure that all changes are properly reflected.
    
    If these solutions do not resolve the issue, it might be worth checking if there are any conflicting layout files in the application or if there are any errors in the code that might be preventing the default layout file from being loaded.
    

  2. sama clif 0 Reputation points
    2023-05-08T04:13:25.7666667+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.

    0 comments No comments