Try our conversational search powered by Generative AI!

Menu link depending upon if we are logged in or not

Vote:
 

Is there a way to show/hide an item in the menu depending upon the role or depending upon if you are logged into or not?

#184785
Nov 03, 2017 13:52
Vote:
 

Hi, Chaudhry,

Do you mean the menu item on the website or inside edit mode?

If inside the website, you can check out AlloyTech templates, there you have helpers for rendering a menu. They take the role into account. Take a look at public static IHtmlString MenuList, specifically the call to FilterForDisplay.

If you are talking about edit mode, check out this post, but make sure to read the comments!

BR,
Marija

#184867
Nov 06, 2017 13:46
Vote:
 

Hi Marija,

Yes I am talking about the menu inside the website. The issue I was having was because of the custom login for website users I have made. And there I was having issue setting roles etc as the user was being authenticated through an external api and not the standard way in Episerver

#184958
Nov 07, 2017 8:24
Vote:
 

Hi,

Then you have a bit bigger issue than menus in particular. You need to set your authentication and authorization architecture, so that Episerver understand the user and its roles. I would advise you to put time to it, given that more things might not work for you later on.

If you are using Owin, you should be setting user and role claims based on external authentication. If not so, a membership and role provider implementation should be done.

Then, the rest requires no special approach, it will work with Alloy-like code. 

BR,
Marija

#184965
Nov 07, 2017 14:09
Vote:
 

Hi,

Yes I think I have covered the authentication properly usin OWIN middelware. There I have a handler which handles the login using the api and then I add roles and claims. 

#185078
Nov 09, 2017 8:25
Vote:
 

Hey,

Then it should work with FilterForDisplay...

You could implement the Owin part to Alloy to debug that and see where the problem is, but for me, it's difficult to help you without further info...

BR,
Marija

#185087
Nov 09, 2017 10:36
* 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.