Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

How to redirect directly to login Page instead of home page if User not logged in to Portal

(0) ShareShare
ReportReport
Posted on by

Hello Experts,

Please help me with the implementation of following requirement in D365 Portals:

If User is not logged in, they should be redirected directly to sign in page on entering the portal URL

Else 

If User has signed in, then they should be redirected to the home page.

  • Community Member Profile Picture
    on at
    RE: How to redirect directly to login Page instead of home page if User not logged in to Portal

    Hi Mahender,

    Thanks a lot for your response. This worked for me.

    Actually I was trying with the following code in Custom Javascript of Home web page

    {% if user %}

    {% else if %}

    window.open('https://'+window.location.host+'/SignIn?returnUrl='+window.location.pathname,'_self');

    {% endif %}

    This did not work as the Signin page is continuously blinking.

    But your code in Home web template worked.

    Thanks Again!

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: How to redirect directly to login Page instead of home page if User not logged in to Portal

    Hi DevDynm,

    You can use user(docs.microsoft.com/.../liquid-objects)  object to identify if user is signed in or not, you can use following script on your the web template

    {% if user %}

    {% else %}

    window.location.href = "/SignIn?returnUrl=%2F"; //redirect them to sign page

    {% endif %}

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Dynamics 365 general forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans