Redirecting User to Specific Page After Login to Dynamics 365 Portal

Requirement: Support user should be redirected to support page after login to Dynamics 365 portal instead of home page. But later they can navigate to home page.

Solution– In order to implement this requirement, here we need to implement two checks:
1. Check if user is a support user.
2. Check if he is navigating to home page for the first time after login.

To implement first requirement, we are going to use User object here to check if current user is part of the Portal Support User web roles, if you are new to web roles, please refer this KB for how to create web roles.

 {% if user.roles contains 'Portal Support User'%}

Now to implement second requirement, I don’t find any straight out of the box configuration to redirect user to specific page after every login. Off course they will be redirect to Profile page for the first time login. But we can implement a workaround by writing quick javascript code to implement this requirement. We can use sessionStorage here to hold a flag to validate it. session storage is specific tab or page, so once it is closed, value of the session storage removed automatically. So we are going to use Home web template and will be using following code on the Home template, so navigate to Portals-> Web Templates and open Home template
Home
And use following code:

<script type="text/javascript">
            if(window.sessionStorage) {
              if(!(sessionStorage.getItem("firstredirect")))
              {
                     sessionStorage.setItem("firstredirect","1");
                     window.location.href = "/support";
              }
               }
           </script>

Our full code should look like below:

customer service
Save your changes now, now when user will login he will be automatically redirected to support page.
If you are not able to see changes, try to clear Portal Cache.

One thought on “Redirecting User to Specific Page After Login to Dynamics 365 Portal

  1. Andreas

    Hi, i am using this code to redirect two different user roles. The problem is it looks like it’s just skipping the liquid code part and running the fist JS no matter what user role i am trying to login with. Any ideas to what i can do?
    This i my code right now

    {% if user.roles contains ‘Konsulent rolle’%}

    if(window.sessionStorage) {
    if(!(sessionStorage.getItem(“firstredirect”)))
    {
    sessionStorage.setItem(“firstredirect”,”1″);
    window.location.href = “/portal2”;
    }
    }

    {% elsif user.roles contains ‘kunde kontakt rolle’%}

    if(window.sessionStorage) {
    if(!(sessionStorage.getItem(“firstredirect”)))
    {
    sessionStorage.setItem(“firstredirect”,”1″);
    window.location.href = “/kundekontakt”;
    }
    }

    {% endif %}

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *