Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - Power Apps Portals
Unanswered

Return Login URL

(0) ShareShare
ReportReport
Posted on by 20

Hi,

I’ve been trying to implement a redirect after sign-in that takes the user back to the original page they were viewing before authentication. However, the user is consistently redirected to the profile page instead.

I want to ensure the user is redirected back to the previous page URL, including any appended query parameters or record IDs. I've included the code snippet I'm currently working with (see below).

Can you please advise if this redirection can be handled through site settings, or does it require custom JavaScript or server-side code?

 

Thanks for your help!

 

  <div class="alert alert-danger text-center justify-content-center align-items-center" role="alert"
    style="margin: 0 auto; color: red;">
    <a id="loginLink" href="#"><b>"Click Here TO LOGIN"</b></a>
  </div>
 
 
<script>
  function updateLoginLink() {
    try {
      var currentUrl = window.location.pathname + window.location.search;
      var encodedCurrentUrl = encodeURIComponent(currentUrl);
      var signInUrl = "/SignIn?returnUrl=" + encodedCurrentUrl;
      var loginLink = document.getElementById('loginLink');
      if (loginLink) {
        loginLink.href = signInUrl;
      } else {
        console.error('Login link element not found!');
      }
    } catch (error) {
      console.error('An error occurred while setting the login link:', error);
    }
  }
  document.addEventListener('DOMContentLoaded', function () {
    var loginLink = document.getElementById('loginLink');
    if (loginLink) {
      loginLink.addEventListener('click', function (event) {
        event.preventDefault();
        updateLoginLink();
        window.location.href = loginLink.href;
      });
    }
  });
</script>
Categories:

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >