In our ASP.NET Core application we have several roles, we want each role has its own layout, for doing this we came up with idea of having separate layout for each role:
~/Views/Shared/Layouts/_DefaultLayout.cshtml
~/Views/Shared/Layouts/_Role_1_Layout.cshtml
~/Views/Shared/Layouts/_Role_2_Layout.cshtml
~/Views/Shared/Layouts/_Role_3_Layout.cshtml
~/Views/Shared/Layouts/_Role_4_Layout.cshtml
For switching between these roles we modify the ~/Views/_ViewStart.cshtml to this:
@{
if (this.User.IsInRole("Role1"))
{
Layout = "~/Views/Shared/Layouts/_Role_1_Layout.cshtml";
}
else if (this.User.IsInRole("Role2"))
{
Layout = "~/Views/Shared/Layouts/_Role_2_Layout.cshtml";
}
// ....
else
{
Layout = "~/Views/Shared/_DefaultLayout.cshtml";
}
}
this works in the first place, but when I log in with another user with for example Role1, instead of switching the current layout to use _Role_1_Layout.cshtml, it displays a blank page.
Any idea?