{"id":2983,"date":"2018-05-24T11:10:02","date_gmt":"2018-05-24T11:10:02","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=2983"},"modified":"2018-05-24T11:10:02","modified_gmt":"2018-05-24T11:10:02","slug":"redirecting-user-to-specific-page-after-login-to-dynamics-365-portal","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=2983","title":{"rendered":"Redirecting User to Specific Page After Login to Dynamics 365 Portal"},"content":{"rendered":"<p><strong>Requirement<\/strong>: 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.<\/p>\n<p><strong>Solution<\/strong>&#8211; In order to implement this requirement, here we need to implement two checks:<br \/>\n1. Check if user is a support user.<br \/>\n2. Check if he is navigating to home page for the first time after login.<\/p>\n<p>To implement first requirement, we are going to use <a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/portals\/liquid-objects#user\">User <\/a>object here to check if current user is part of the Portal Support User web roles, if you are new to web roles, please <a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/portals\/create-web-roles\">refer this KB<\/a> for how to create web roles.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n {% if user.roles contains 'Portal Support User'%}\r\n<\/pre>\n<p>Now to implement second requirement, I don&#8217;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 <a href=\"https:\/\/www.w3schools.com\/jsref\/prop_win_sessionstorage.asp\">sessionStorage<\/a> 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-&gt; Web Templates and open Home template<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/05\/Home.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-2987 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/05\/Home-300x185.jpg\" alt=\"Home\" width=\"300\" height=\"185\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/05\/Home-300x185.jpg 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/05\/Home-624x385.jpg 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/05\/Home.jpg 738w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nAnd use following code:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;script type=&quot;text\/javascript&quot;&gt;\r\n            if(window.sessionStorage) {\r\n              if(!(sessionStorage.getItem(&quot;firstredirect&quot;)))\r\n              {\r\n                     sessionStorage.setItem(&quot;firstredirect&quot;,&quot;1&quot;);\r\n                     window.location.href = &quot;\/support&quot;;\r\n              }\r\n               }\r\n           &lt;\/script&gt;\r\n<\/pre>\n<p>Our full code should look like below:<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/05\/customer-service.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-2985 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/05\/customer-service-300x152.jpg\" alt=\"customer service\" width=\"300\" height=\"152\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/05\/customer-service-300x152.jpg 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/05\/customer-service-624x317.jpg 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/05\/customer-service.jpg 871w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nSave your changes now, now when user will login he will be automatically redirected to support page.<br \/>\nIf you are not able to see changes, try to clear Portal Cache.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8211; 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&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=2983\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,402,508],"tags":[512,514,513],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2983"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2983"}],"version-history":[{"count":11,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2983\/revisions"}],"predecessor-version":[{"id":3000,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2983\/revisions\/3000"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}