PowerApps Portals – Change Default Landing Page For Portal Users

Hi All,

Welcome to my Power Guide Mentorship Program.

Today, I am going to share a #PowerGuideTip16 for PowerApps Portal Developers, who want to manage the redirection of the Portal default landing page.

Requirement:

Redirect Anonymous Portal User to Login Page and Authenticated Portal Users to Home Page,

Solution:

Option 1 – 
Anonymous User Default Landing Page – Login Page
Authenticated User Default Landing Page – OOB Home Page

Go to Portals > Web Template > Home

Update the code as per the following:

{% if user %}
//if a user is logged in then
// Paste OOB Home web template Liquid Code inside this block
{% else %}

<script>
//if user is not loggedin, redirect user to Login page
window.location.href=\’~/SignIn\’;
</script>

{% endif %}


Option 2 – 
Anonymous User Default Landing Page – Login Page
Authenticated User Default Landing Page – Custom Page or other than OOB Home Page

{% if user %}
//if a user is logged
<script>
window.location.href=\’~/\’;
</script>
{% else %}

<script>
//if user is not loggedin, redirect user to Login page
window.location.href=\’~/SignIn\’;
</script>

{% endif %}


Option 3 – 
Sometimes, you might have the requirement to redirect portal users to the same page after login, where he/she left off, even after closing the browser.

To implement this requirement, you need to use the HTML Local Storage feature.

Set Local Storage –

You need to save the webpage name in Local Storage (browser cache) on each webpage load.

For Example – Let say I have a webpage called submit-request (partial url of webpage), which is associated with case entity form. In order to save the webpage name in local storage. I would use following syntax under Custom JavaScript section:

// Store
var getWebpagePartialURL = location.pathname;
localStorage.setItem(\”webpagename\”getWebpagePartialURL); 


Get Local Storage – 

Now, Go to Home Web Template. You need to write the code to get the local storage value in order to know the webpage name that user had accessed last before closing the browser. And redirect the user accordingly.

{% if user %}
//if a user is logged
<script>
// Retrieve local storage value
var lastAccessedPage = localStorage.getItem(\”webpagename\”);
if (lastAccessedPage != null && lastAccessedPage != \’\’)
{
window.location.href = \’~/\’lastAccessedPage ;
}
</script>
{% else %}

<script>
//if user is not loggedin, redirect user to Login page
window.location.href=\’~/SignIn\’;
</script>

{% endif %}

Published by arpitpowerguide

My name is Arpit Shrivastava, who is a Microsoft MVP in the Business Applications category. I am a Microsoft Dynamics 365 and Power Platform enthusiast person who is having a passion for researching and learning new things and acquiring immense knowledge. I am providing consistent help, support, and sharing my knowledge through various Social Media Channels along with my Personal Blog, Microsoft Community, conducting online training and attending various 365 Saturday Events worldwide and sharing the best Solutions to the readers helping them achieve their goals and objectives in Customer Relationship Space.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: