本文整理汇总了C#中UserManager.hasClaim方法的典型用法代码示例。如果您正苦于以下问题:C# UserManager.hasClaim方法的具体用法?C# UserManager.hasClaim怎么用?C# UserManager.hasClaim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserManager
的用法示例。
在下文中一共展示了UserManager.hasClaim方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Index
public ActionResult Index()
{
UserManager manager = new UserManager();
var userId = (ClaimsIdentity)User.Identity;
bool teacher = manager.hasClaim(User.Identity.Name, ClaimTypes.Role, "teacher");
bool admin = manager.hasClaim(User.Identity.Name, ClaimTypes.Role, "admin");
if (!teacher && !admin) {
return RedirectToAction("Index", "Home");
}
return View(db.Users.ToList());
}
示例2: AdminTeacherCheck
public AdminTeacherCheck(string name)
{
access = 0;
if (name.Equals("") || name == null)
{
return;
}
UserManager mgr = new UserManager();
if (mgr.hasClaim(name, "teacher"))
{
access++;
}
if (mgr.hasClaim(name, "admin"))
{
access += 2;
}
}
示例3: Index
public ActionResult Index()
{
UserManager manager = new UserManager();
bool role = manager.hasClaim(User.Identity.Name, ClaimTypes.Role, "admin");
if (!role) {
return RedirectToAction("Index", "Home");
}
//UserManager manager = new UserManager();
List<UserView> Determination = new List<UserView>();
foreach (var user in db.Users.ToList()) {
Determination.Add(new UserView(user));
}
return View(Determination);
}
示例4: Edit
public ActionResult Edit(string id)
{
UserManager manager = new UserManager();
User user = manager.findById(id);
bool role = manager.hasClaim(id, ClaimTypes.Role, "admin", false);
if (role) {
ViewBag.AdminLockout = "Do not try to lock yourself out!";
return RedirectToAction("Index", "Administrator");
}
if (user == null) {
return HttpNotFound();
}
return View(user);
}
示例5: UserView
public UserView(User user)
{
UserManager manager = new UserManager();
Users = user;
if (manager.hasClaim(user.UserName, "teacher")) {
userRole = "Teacher";
}
else if (manager.hasClaim(user.UserName, "admin")) {
userRole = "Admin";
}
else {
userRole = "Student";
}
}