User is in role “admin” but [Authorize(Roles=“admin”)] won't authenticate

前端 未结 2 572
Happy的楠姐
Happy的楠姐 2020-12-08 11:57

I found a great answer on SO describing how to set up custom user roles, and I\'ve done the same in my project. So in my Login service I have:

public Action         


        
2条回答
  •  自闭症患者
    2020-12-08 12:46

    I would change principal assign at first:

    Thread.CurrentPrincipal = userPrincipal;
    if (HttpContext.Current != null)
    {
        HttpContext.Current.User = userPrincipal;
    }
    

    as ASP.NET documentation stands.

提交回复
热议问题