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

百般思念 提交于 2019-11-29 09:36:08
if (User.IsInRole("rolename")) {
  // my action
}

Easy~

HttpContext.Current.User.IsInRole("roleName")
Matthew Jones

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

I use these all the time.

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();
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!