我正在关注此代码随附的教科书: these docs
但是,我导航到的路线之一不会继承SportsStore / Pages / Admin / AdminLayout.razor提供的布局。不继承引导布局的页面是SportsStore / Pages / Admin / IdentityUsers.csthml文件。 Pages / Admin目录中的所有其他文件都显示正确的布局。
这些Razor页面如何继承AdminLayout.razor
文件?我以为是通过Routed.razor
文件进行的:
@using Microsoft.AspNetCore.Components.Authorization
<Router AppAssembly="typeof(Startup).Assembly">
<Found>
<RouteView RouteData="@context" DefaultLayout="typeof(AdminLayout)" />
</Found>
<NotFound>
<h4 class="bg-danger text-white text-center p-2">
No Matching Route Found
</h4>
</NotFound>
</Router>
这是我的Startup.cs文件中的路由:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("typepage",
"{type}/Page{modelPage:int}",
new { Controller = "Home", action = "Index" });
endpoints.MapControllerRoute("page", "Page{modelPage:int}",
new { Controller = "Home", action = "Index", modelPage = 1 });
endpoints.MapControllerRoute("type", "{type}",
new { Controller = "Home", action = "Index", modelPage = 1 });
endpoints.MapControllerRoute("pagination",
"Models/Page{modelPage}",
new { Controller = "Home", action = "Index", modelPage = 1 });
endpoints.MapDefaultControllerRoute();
endpoints.MapRazorPages();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/admin/{*catchall}", "/Admin/Index");
});
和我的IdentityUsers.cshml
文件:
@page
@model IdentityUsersModel
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.Authorization
<h3 class="bg-primary text-white text-center p-2">Admin User</h3>
<table class="table table-sm table-striped table-bordered">
<tbody>
<tr><th>User</th><td>@Model.AdminUser.UserName</td></tr>
<tr><th>Email</th><td>@Model.AdminUser.Email</td></tr>
<tr><th>Phone</th><td>@Model.AdminUser.PhoneNumber</td></tr>
</tbody>
</table>
@functions{
[Authorize]
public class IdentityUsersModel : PageModel
{
private UserManager<IdentityUser> userManager;
public IdentityUsersModel(UserManager<IdentityUser> mgr)
{
userManager = mgr;
}
public IdentityUser AdminUser { get; set; }
public async Task OnGetAsync()
{
AdminUser = await userManager.FindByNameAsync("Admin");
}
}
}