Developer forum

Forum » CMS - Standard features » Force login for anonymous users on protected pages

Force login for anonymous users on protected pages

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

We have a Swift implementation where we have the entire "My account" section protected.

We are trying to achieve a solution for redirecting the user to a login page (or displaying the login template) if a user tries to access a protected page without being authenticated.
I have set up a Login template on the website settings and also I have set up the permission on the entire page tree. The 404 redirect is set on the website settings and I assume it is already set correctly in IIS since it is a cloud solution

However, when trying to access a protected page as anonymous, I get this nasty yellow error:

From the error stack, it seems that it may try to open the login dialog ( Pageview.GetLogonDialog() )

Is there any setting that I am missing? I imagine this should be standard behavior.

Thank you,

Adrian


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Adrian

I would say that is default behavior. If you access https://swiftdemo.dynamicweb-cms.com/my-account or /my-account/dashboard you get the login page.

This logic is handled in the Swift_page.cshtml template: https://github.com/dynamicweb/Swift/blob/main/Swift/Files/Templates/Designs/Swift/Swift_Page.cshtml#L101

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you for the confirmation.

I believe that I was expecting the Login template from the Website settings to kick in.

But we can make it work as on the Swift page. Strange enough, our solution is Swift. But it was started from an earlier version and maybe we have missed this sign-in logic.

Thank you,

Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

The login template selector for pages and websites have been 'deprecated' for 10+ years or so. We do not use them at all and in DW10 they are gone. Finally.

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Good to know!

Thank you,

Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

I have been whispered in my ear that I currently might be wrong here. I might be thinking of something else....!

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

:)

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

I have checked out our template and apparently, we do have the same Swift logic in the master page.

It just seems that the !Model.IsCurrentUserAllowed check does not seem to work. As it does not Redirect and it keep the same link instead.

We are using 9.13.14 in this particular project. Could there be any bug related to permissions in this version?

Thank you,
Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

I cannot remember if we made changes. But you can test on a newer version.

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Adrian,

The exception in your original post indicates that there is a problem with rendering of the login dialog based on a razor template.
The login template is inherited from any parent pages and the website.
On you soulution the page "Min konto" (id: 112) has Login.cshtml selected, but that template doesn't exist anymore.
It seems that we currently don't handle it very well when a non-existing login template is selected.
Try to select another template (or none) on page 112 and see if that solves your problems.

/Morten
 

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Morten,
Thank you for the suggestion. I have changed it and I can confirm it now works as expected.

It would be nice if this error would be handled better.

Thank you,

Adrian

 

You must be logged in to post in the forum