3

I have two kind of user in my portal, a customer user and an agent user. I want to change the default Homepage of Agent user every time he/she logs in or clicks to a Homepage button to the website instead of the customer's default homepage.ie (Agent Homepage) Currently, I was able to achieve this through below code:

var userId = AuthenticationManager.AuthenticationResponseGrant.Identity.GetUserId();
var user = await UserManager.FindByIdAsync(userId);

var portal = PortalCrmConfigurationManager.CreatePortalContext();
var usercontext = portal.User;
var context = portal.ServiceContext;
var contact = (from c in context.CreateQuery("contact")
               where c["contactid"].Equals(userId)
               select c).First();
var isAgentUser = contact.GetAttributeValue<bool>("bh_isagentuser");

if (isAgentUser == true)
{
    return Redirect("/agent-home");
}
else
{
    return RedirectToLocal(returnUrl);
}

I want to know if there's another workaround for ADX studio to achieve this?

Komal12
  • 3,340
  • 4
  • 16
  • 25
r-r
  • 307
  • 2
  • 15

1 Answers1

0

Rather than redirecting to a different web page, you could change what information is displayed on the home page based on the detected user type. A simple example using Liquid would be to include a different web template depending on the user type:

{% if user.bh_isAgentUser %}
  {% include "Agent Home" %}
{% else %}
  {% include "Default Home" %}
{% endif %}

You would add the different home page rendering logic inside each of the Agent Home and Default Home web templates.

The above Liquid could be inserted into the copy field of the home page, or the home page could be changed to use a web template with this Liquid inside it. This choice would depend on the structural elements of the rendered web page that need to change.

See documentation on the user object, include tag, and web templates for more details.

Alan Mervitz
  • 507
  • 5
  • 15