asp.net membership - how to determine programmatically is user is in role

前端 未结 4 1902
礼貌的吻别
礼貌的吻别 2020-12-19 00:02

What is the code for determining if a user is in a role?

I have set up all the users through the ASP.NET Configuration Security tab but now want to put logic around

相关标签:
4条回答
  • 2020-12-19 00:38
    if (User.IsInRole("rolename")) {
      // my action
    }
    
    0 讨论(0)
  • 2020-12-19 00:39

    Check out the Roles class, specifically IsUserInRole, GetUsersInRole, AddUserToRole, etc.

    I use these all the time.

    0 讨论(0)
  • 2020-12-19 00:40

    Easy~

    HttpContext.Current.User.IsInRole("roleName")
    
    0 讨论(0)
  • 2020-12-19 00:51

    thanks to "Chris Van Opstal". i solved my problem like this way,

        public ActionResult Index()
        {
    
            if (User.IsInRole("Supervisor"))
            {
                return RedirectToAction("Index", "InvitationS");
            }
            return View();
        }
    
    0 讨论(0)
提交回复
热议问题