1

Looking for some advice, I have a bool property value on a user object that indicates if the user is an admin. I have some menu links on my view, which if your an admin I want to show(other wise dont show), I also want to ensure that the controller has an attribute that checks to ensure the user is an admin, so whats the best way to implement this, examples welcomed.

1
  • 4
    Why aren't you just using Roles? That's what they're for. Commented Jun 13, 2013 at 18:54

1 Answer 1

2

Here is my attribute for navigation build

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public sealed class NavigationItemAttribute : System.Attribute
{
    public NavigationItemAttribute(string text)
    {
        Text = text;
        SortOrder = int.MaxValue;
        ActionName = "Index";
        Category = Category;
        IconClass = IconClass;
        Domain = Domain;
    }

    public string Text { get; private set; }
    public string Area { get; set; }
    public int SortOrder { get; set; }
    public string ActionName { get; set; }
    public string Category { get; set; }
    public string IconClass { get; set; }
    public string Domain { get; set; }
}

and usage

[NavigationItem("!lang:navigation:admin_main!", SortOrder = 6, Domain = "main", IconClass = "icon-user")]
public class MembershipController : Controller

but roles using anyvay to show or not show item

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.