web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Pages - Power Apps Portals
Unanswered

Return Login URL

(3) ShareShare
ReportReport
Posted on by 53

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:
I have the same question (0)
  • Suggested answer
    Shafiuddin Profile Picture
    65 on at
    Return Login URL
    Hello,

    This isn’t controlled by a simple site setting, you’ll need the JS workaround (or deeper customization).

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

MS.Ragavendar – Community Spotlight

We are honored to recognize Ragavendar Swaminatha Subramanian as our September…

Leaderboard > Power Pages

#1
Jon Unzueta Profile Picture

Jon Unzueta 103 Super User 2025 Season 2

#2
KevinGador Profile Picture

KevinGador 32 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 32

Last 30 days Overall leaderboard