2009-07-31 70 views

回答

22
if (User.IsInRole("rolename")) { 
    // my action 
} 
+0

用户名是什么命名空间? – leora 2009-07-31 18:01:25

+3

用户是Page和HttpContext类的一个属性,因此您可以在页面上以用户身份或在HttpContext.Current.User的非页面文件中访问它。更多信息在MSDN:http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx – 2009-07-31 18:08:30

2

退房的Roles类,具体的isUserInRole,GetUsersInRole,AddUserToRole等

我使用这些所有的时间。

2

感谢 “克里斯·范·Opstal”。我以这种方式解决了我的问题,

public ActionResult Index() 
    { 

     if (User.IsInRole("Supervisor")) 
     { 
      return RedirectToAction("Index", "InvitationS"); 
     } 
     return View(); 
    } 
相关问题