2

I have sitecore form with dropdown control that have 8 values coming from sitecore. i need to show all 8 for anonymous users and only 4 for logged in users. How to achieve this

3 Answers 3

1

I think it's good to add security on Role instead of user which can give more flexibility. As dropdown values are coming from Sitecore you can restrict read access of role. So if it is coming from OKTA I think still you have mapping roles in Sitecore and you can restrict read access on the role which is applied to your user.

So it will be accessible for Anonymous user but will not render to the for user which is having particular role.

0

I think you can achieve it by using Sitecore security. As values come from Sitecore, you can set security on it. If you deny read access to your logged-in users for those 4 items that you don't want to show for logged-in users it will not be visible. Anonymous users who do have read access will still see the all values in the dropdown.

Read more :Assign access rights to a security account

Hope it helps!

2
  • logged users means logged in using some third party tools like OKTA.
    – udit
    Commented Feb 9 at 6:09
  • Yes, it should work fine with OKTA user. You need to deny read access on role and map that role to users. Commented Feb 9 at 7:40
0

Another way to do that is to create a custom dropdown list and override the logic where you can get the datasource items and check the current user role like this.

User currentUser = Sitecore.Context.User;

// Determine if the user is in a specific role
bool isInRole = currentUser.IsInRole("YourRoleName");

And check if the user has access to the items.

// Check if the current context user 
// have read access to the item
bool canRead = item.Access.CanRead();

And create a datasource for your dropdown by checking the permissions. And pass this new datasource to your control to bind the values.

You can refer to this article to customize your control in Sitecore.

enter link description here

And this to work on security.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.