Using ASP.NET Identity for a Role Provider easily

前端 未结 2 1350
孤街浪徒
孤街浪徒 2021-01-14 01:49

I just spent the last two days researching and implementing the new ASP.NET Identity system with my existing database. More on that here: Integrating ASP.NET Identity into E

2条回答
  •  生来不讨喜
    2021-01-14 01:58

    Did you remember to put your application name in your web config?

    
       
          
            
        
           
    

    Use one of the following in your controllers.

    [Authorize] //Anyone with authorization
    [Authorize(Roles="Administrator")] //Admin role only
    

    You could also do something like this.

    HttpContext.User.IsInRole("Administrator")
    UserManager.IsInRole(userID, "Administrator")
    

提交回复
热议问题