ASP.NET 2.0的身份检查,如果当前用户是角色IsInRole [英] ASP.NET Identity 2.0 check if current user is in role IsInRole

查看:290
本文介绍了ASP.NET 2.0的身份检查,如果当前用户是角色IsInRole的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ASP.NET 2.0的身份,你如何检查,如果当前登录的用户是一个角色?我使用的是下面的,但不知道是否有什么更有效。

  VAR微米=新的UserManager< ApplicationUser>(新UserStore< ApplicationUser>(新的DbContext()));
变种AU = um.FindByEmail(Context.User.Identity.GetUserName());
VAR inrole = um.IsInRole(au.Id,管理);如果(inrole)
{
}


解决方案

在ASP身份的正确方法是为

一样简单

  User.IsInRole(角色名);

With ASP.NET Identity 2.0 how do you check if the currently logged on user is in a role? I am using the following, but wondering if there is something more efficient.

var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new DbContext()));
var au = um.FindByEmail(Context.User.Identity.GetUserName());
var inrole = um.IsInRole(au.Id, "Admin");

if (inrole)
{
}

解决方案

The correct way in ASP Identity is as simple as

User.IsInRole("rolename");

这篇关于ASP.NET 2.0的身份检查,如果当前用户是角色IsInRole的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆