How to Show or hide controls based on roles - ASP.NET MVC 4 Razor

前端 未结 3 1922
旧巷少年郎
旧巷少年郎 2020-12-29 07:43

I m working on ASP.NET MVC 4 application.I have a dashboard and my users groups will be based on Windows Domain So I am using WIndows Authentication for authenticating users

3条回答
  •  鱼传尺愫
    2020-12-29 08:04

    You can use Following code for role based checking

    @if(Request.IsAuthenticated)
    
    {
        if(User.IsInRole("Admin"))
        {
         
        }
         if(User.IsInRole("User"))
        {
         
        }
    }
    @* For unknown user *@
    else
    {
         
    }
    

提交回复
热议问题