AronChan
AronChan

Reputation: 245

Calling a method in my HomeController from my Masterpage

Im trying to hide some admin specific buttons on my masterpage from users with no adminrights.

my code looks like this so far:

<% if (Request.IsAuthenticated)
    {%>
        <%: Html.ActionLink("Administrer", "Index", "User", new { Area = "Users" }, new { @class = "menubutton", @id = "settingsbutton" })%>
      <%} else { }%>

now i want to do a check in the IF() statement if the current user is an administrator. im using the ASP.NET membership system and have a speciel class attached to each user with some exstra information including information about if he is an admin or not (bool).

my question is how do i go about calling a method that checks this or something similar?

Upvotes: 0

Views: 155

Answers (1)

danludwig
danludwig

Reputation: 47365

<% if (Request.IsAuthenticated && User.IsInRole("Administrator"))
    {%>
        <%: Html.ActionLink("Administrer", "Index", "User", new { Area = "Users" }, new { @class = "menubutton", @id = "settingsbutton" })%>
      <%} else { }%>

If you are using the ASP.NET Membership Provider and the ASP.NET Role Provider to link your users to their roles, you can just invoke the IsInRole(string) method on your view's IPrincipal User object.

Upvotes: 3

Related Questions