You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET Core Identity布局文件缺失:无法找到指定_Layout.cshtml

解决ASP.NET Core Identity布局缺失及Logo显示问题

Hey there, let's work through these two issues one by one—they're both fixable with straightforward steps:

1. 修复缺失的 /Areas/Identity/Pages/_Layout.cshtml 文件

Identity scaffolding doesn't automatically generate this root layout file, so manual creation is the way to go:

  • Navigate to your project's Areas/Identity/Pages directory
  • Right-click and select Add > New Item, then create a Razor Layout file named _Layout.cshtml
  • Copy the content from your existing Views/Shared/_Layout.cshtml into this new file (or customize it to match your project's design—just make sure to keep core parts like @RenderBody() and script references)

Here's a simplified example of what the file could look like:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - YourProjectName</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
</head>
<body>
    <!-- Copy your header + logo code from Views/Shared/_Layout.cshtml here -->
    <header class="navbar navbar-expand-sm navbar-light bg-white border-bottom box-shadow">
        <div class="container">
            <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">
                <img src="~/images/your-logo.png" alt="Project Logo" height="35" />
                YourProjectName
            </a>
            <!-- Add other navigation links as needed -->
        </div>
    </header>
    <div class="container mt-4">
        <main role="main">
            @RenderBody()
        </main>
    </div>

    <footer class="border-top text-muted mt-5">
        <div class="container">
            &copy; 2024 YourProjectName - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
        </div>
    </footer>

    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    @await RenderSectionAsync("Scripts", required: false)
</body>
</html>

2. 修复个人资料页的Logo显示问题

The logo wasn't showing because the Identity layout file was missing, forcing the Manage page to use a barebones default layout. Now that we've created the correct layout, just verify these two things:

  • Use root-relative paths for the logo: In your new Identity _Layout.cshtml, set the logo's src to ~/images/your-logo.png (the ~ points to your website's root directory, so it works no matter which area the page is in)
  • Confirm the logo file exists: Make sure your logo is in the wwwroot/images folder, and that its properties are set to "Copy to Output Directory" (right-click the file > Properties > Copy to Output Directory: Copy if newer)
  • Double-check the Manage layout reference: Open Areas/Identity/Pages/Account/Manage/_Layout.cshtml and ensure it's pointing to the correct layout:
    @{
        Layout = "/Areas/Identity/Pages/_Layout.cshtml";
    }
    

After making these changes, rebuild and run your project. The profile page should now display your logo just like the home page does.

内容的提问来源于stack exchange,提问作者Hamza Khanzada

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:17:40