Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Anonymous Visitor Group

Vote:
 

Hello!

I am trying to implement a feature where a block is invisible if an authenticated user is viewing the site, and visible if it is being viewed by an anonymous visitor.

My first thought was to use visitor groups, because it allows the content author to toggle the view and know how it will look based on each state. However, I do not see that you can use logged in state to control a visitor group unless I am mistaken.

What is the preferred way to handle this use case? Currently I have wrapped my block in a check @if (!User.Identity.IsAuthenticated), but it is not ideal because the content author won't see it.

Thanks for any advice!

#206126
Aug 02, 2019 20:58
Vote:
 

Not a perfect solution but you can combine that check with a check if it is in Edit mode instead

#206127
Aug 02, 2019 21:40
Vote:
 

Hi,

You certainly can create a visitor group based on whether the user's logged in though it's not one of the out of the box criteria. I've written similar before and it was quite straightforward but, if you don't fancy writing it yourself you might be able to use the role criterion which you can add through nuget:

https://nuget.episerver.com/package/?id=RoleCriterion

Just as a word of warning - I seem to recall that the rolecriterion package had a few quirks when used with identity rather than membership providers but that may just have been our project (it had lots of customisation around the authentication mechanism).

#206129
Aug 02, 2019 22:08
Vote:
 

I think you must click on Toggle View Settings icon, then click on View as ... icon. In my test, I have a block that is only visible to anonymous user, in Edit View, logged user cannot see it

But if I choose view as Anonymous user, it's visible to Editor

#206165
Aug 06, 2019 3:56
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.