简体   繁体   中英

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?

<% 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM