Role-Based Content asp.net mvc

后端 未结 4 408
-上瘾入骨i
-上瘾入骨i 2020-12-29 00:21

I wish to display content depending on the given role(s) of the active user , in the ASP.NET MVC.

Compare the old fashion way, using WebForms:

protec         


        
4条回答
  •  时光说笑
    2020-12-29 00:54

    this worked for me:

     <% MembershipUser mu = Membership.GetUser();
                        if (mu != null)
                            if (Roles.IsUserInRole(mu.UserName, "Administrator"))
                            {
                         %>
                    
  • <%= Html.ActionLink("User Administration", "GetUsers", "Account")%>
  • <%} %>

提交回复
热议问题