Hello Kentico Community,I am currently working on a Kentico 13 MVC application that essentially has two @homepages@ depending on whether a user is logged in or not. I have set up Content-Based Routing in Kentico, and the majority of the system is working as intended. However, I am facing a challenge with the initial request to the root (@/@) when the user is authenticated.Here's my code in _ViewStart.cshml@{
if (Context.User.Identity?.IsAuthenticated ?? false)
{
Layout = @~/Views/Shared/_DashboardLayout.cshtml@;
}
else
{
Layout = @~/Views/Shared/_HomeLayout.cshtml@;
}
}
Everything works perfectly, except the first request to @/@ when redirected to @/{culture}@.
During this first request, I get an exception:InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Kentico.PageBuilder.Web.Mvc.ComponentDefaultViewModel1[Generic.Features.Home.HomePageTemplateProperties]', but this ViewDataDictionary instance requires a model item of type 'Generic.Features.Dashboard.DashboardViewModel'.As I understand, this is happening because of the model type expected during the initial request, but I'm at a loss as to how to work around this situation.The core question here is: What changes do I need to make to ensure that the initial @/@ calls the @/Dashboard@ controller when the user is authenticated, and not the via the Kentico PageBuilder?I would appreciate insights into the best practices for handling this specific scenario, and any guidance you can provide to help resolve this challenge.I am using K13.0.115, MVC, .Net 6 with Content Based Routing.Thank you for your support and looking forward to your valuable feedback!Best Regards, Florian
↧
Best Practices for Implementing Two Layout Variants Based on User Authentication in Kentico 13 MVC
↧