Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Portal: How can I redirect to login page if not logged in?

(0) ShareShare
ReportReport
Posted on by 15

We have a 'My Services' page on the portal and I would like the link to be there irrespective of the user being logged in or not. But if the user is not logged in and clicks on this link he/she should be re-directed to the login page. Is this possible? if yes, how?

*This post is locked for comments

  • Jasbir Dhaliwal Profile Picture
    Jasbir Dhaliwal 15 on at
    RE: Portal: How can I redirect to login page if not logged in?

    Thanks, Arpit. That is exactly what I was looking for.

  • Verified answer
    Arpit Shrivastava Profile Picture
    Arpit Shrivastava 7,518 User Group Leader on at
    RE: Portal: How can I redirect to login page if not logged in?

    Hi Jasbir,

    I may not be aware of your actual requirement. But Ideally, if you do not want to give anonymous access to any of the portal page. you should use Web page Access Control Rules. By using this you can handle the hide/show of web links based on anonymous and authenticated users.

    Alternative option is,

    Use below code under Custom JavaScript section of 'My Services' webpage to achieve your functionality:

    {% if user %}

    {% else if %}

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

    {% endif %}

    For Example - I have used this for 'My Support' page.

    141666.Capture.PNG

     

    You can test it on my portal for 'My Support'  page :

    https://arpitdynamics.microsoftcrmportals.com/

     

    Please mark this answer verified to close this thread.

     

    Cheers

    Arpit

    https://arpitmscrmhunt.blogspot.in

     

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,387 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans