Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
4  
Why aren't you just using Roles? That's what they're for. –  Erik Funkenbusch Jun 13 '13 at 18:54

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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