Redirecting User To Specific Page After Login To Dynamics 365 Portal

The support user should be redirected to support page after logging in to Dynamics 365 portal instead of home page. But later they can navigate to home page.

Requirement

Support user should be redirected to support page after logging in to Dynamics 365 portal instead of the home page. But later they can navigate to the 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 the first requirement, we are going to use User object here to check if current user is part of the Portal Supporting User web roles; if you are new to web roles, please refer to this KB for how to create web roles.

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

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

 
 
And use the following code:
  1. <script type="text/javascript">  
  2.             if(window.sessionStorage) {  
  3.               if(!(sessionStorage.getItem("firstredirect")))  
  4.               {  
  5.                      sessionStorage.setItem("firstredirect","1");  
  6.                      window.location.href = "/support";  
  7.               }  
  8.                }  
  9.            </script>  

Our full code should look like below,

 

Save your changes now, and now when user will login he will be automatically redirected to the support page.

If you are not able to see changes, try to clear Portal Cache.