If you’re using Power Apps portals (now Power Pages) or a similar setup with Azure Active Directory (AD) / Azure B2C logins, you may want users to land on a home page—or different pages depending on how they signed in—rather than the default profile page. Below are the core steps to achieve this, along with examples of handling custom query parameters.
1. Disable the Default Profile Redirect
- In your Portal Management app, go to Site Settings.
- Search for the setting named
ProfileRedirectEnabled
. - Change its value from
true
tofalse
. - Save your changes, then Sync your changes in Power Pages Design Studio (or clear cache if using older portals).
Once disabled, the portal will no longer redirect users to the profile page after sign-in. Instead, they will remain on (or be returned to) the page they were on.
2. Redirect Users to Different Pages Based on How They Signed In
Assume you have two authentication methods:
- Azure AD (referrer might contain
microsoftonline
) - Azure B2C (referrer might contain
b2clogin
)
You want to automatically send them to different pages. You can insert the following script into your Home Page (or any other landing page), either in the JavaScript section or at the top of the HTML for an immediate redirect.
- If you see a brief flicker of the home page before redirect, place this script at the very top of the page (in HTML) so it executes before the page fully loads.
3. Bonus: Passing Query Parameters
You can also handle scenarios where a user clicks a deep link (e.g., including an id
or other parameters in the URL). If the user isn’t authenticated, they’ll be forced to sign in first—but you still want to land them on the correct page with the original parameters.
Imagine a link like:
https://your-portal-url.com/signin?returnUrl=/my-page?id=123
After successful sign-in, you’d like the user to end up on:
https://your-portal-url.com/my-page?id=123
Place a script like the following on your home page (or common landing page) to capture and redirect with the original parameters:
Whenever a user arrives at your site with ?returnUrl=
, the script grabs that path and navigates them there—ensuring they see the intended page (and ID) after sign-in.
Summary
- Disable Profile Redirect: Change
ProfileRedirectEnabled
tofalse
in Site Settings. - Custom Redirect by Referrer: Add a short JavaScript snippet to your home page that checks
document.referrer
and sends the user to the desired page (B2C or AAD). - Handle Query Parameters: If you need to preserve query parameters (like IDs) across sign-in, use a script to detect and redirect after authentication.
These quick edits ensure a seamless user experience, guiding users exactly where you want them to go right after they log in. Feel free to modify the code snippets above to match your specific page URLs and parameter names.
No comments:
Post a Comment