- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 @model IEnumerable<WebApplication.Models.ApplicationUser>
查看
@foreach (var user in Model)
{
<tr>
<td>
@foreach(var role in user.Roles){
role.Name; //invalid
role.RoleId; //valid
role.UserId; //valid
}
</td>
</tr>
}
型号
public class ApplicationUser : IdentityUser
{
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
我可以从这个角色中获取 RoleID 和 UserId,但我如何获取 Role.Name?
IdentityUser [来自元数据]
namespace Microsoft.AspNet.Identity.EntityFramework
{
// Summary:
// Default EntityFramework IUser implementation
//
// Type parameters:
// TKey:
//
// TLogin:
//
// TRole:
//
// TClaim:
public class IdentityUser<TKey, TLogin, TRole, TClaim> : IUser<TKey>
where TLogin : global::Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin<TKey>
where TRole : global::Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole<TKey>
where TClaim : global::Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim<TKey>
{
// Summary:
// Constructor
public IdentityUser();
// Summary:
// Used to record failures for the purposes of lockout
public virtual int AccessFailedCount { get; set; }
//
// Summary:
// Navigation property for user claims
public virtual ICollection<TClaim> Claims { get; }
//
// Summary:
// Email
public virtual string Email { get; set; }
//
// Summary:
// True if the email is confirmed, default is false
public virtual bool EmailConfirmed { get; set; }
//
// Summary:
// User ID (Primary Key)
public virtual TKey Id { get; set; }
//
// Summary:
// Is lockout enabled for this user
public virtual bool LockoutEnabled { get; set; }
//
// Summary:
// DateTime in UTC when lockout ends, any time in the past is considered not
// locked out.
public virtual DateTime? LockoutEndDateUtc { get; set; }
//
// Summary:
// Navigation property for user logins
public virtual ICollection<TLogin> Logins { get; }
//
// Summary:
// The salted/hashed form of the user password
public virtual string PasswordHash { get; set; }
//
// Summary:
// PhoneNumber for the user
public virtual string PhoneNumber { get; set; }
//
// Summary:
// True if the phone number is confirmed, default is false
public virtual bool PhoneNumberConfirmed { get; set; }
//
// Summary:
// Navigation property for user roles
public virtual ICollection<TRole> Roles { get; }
//
// Summary:
// A random value that should change whenever a users credentials have changed
// (password changed, login removed)
public virtual string SecurityStamp { get; set; }
//
// Summary:
// Is two factor enabled for the user
public virtual bool TwoFactorEnabled { get; set; }
//
// Summary:
// User name
public virtual string UserName { get; set; }
}
}
最佳答案
我能找到在 razor 布局 View 中获取角色的唯一方法是从请求中获取 UserManager
。
Razor View :
@using Microsoft.AspNet.Identity
@using Microsoft.AspNet.Identity.Owin;
@if (Request.IsAuthenticated) {
var userManager = Request.GetOwinContext().GetUserManager<ApplicationUserManager>();
var userRoles = userManager.GetRoles(User.Identity.GetUserId());
var role = userRoles[0];
}
关于c# - 如何在 Razor View 中获取 Role.Name?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28882375/
我正在评估在 Azure 中部署 Web 服务的各种选项。目前,Web 服务将仅由前端 UI 使用,该前端 UI 将作为单独的 Web 角色部署在托管 Web 服务的同一云服务中。然而,Web 服务将
我正在尝试在 Azure 中创建一个自定义角色,允许订阅“所有者”执行几乎所有操作,但取消/重命名自己的订阅或移至另一个管理组。 我还希望他们能够向他们想要的人授予正确的访问权限(特别是内置的“贡献者
我是 Ansible 的新手,我已经创建了我的第一个 Ansible 角色剧本,当我尝试运行它时,它抛出了下面的错误,而角色之外的其他模块(如处理程序、模板)工作正常。我仅通过剧本中的角色观察到这个问
我正在使用 Selenium 进行自动化测试。有什么区别 java -jar selenium-server-standalone-2.24.1.jar -role hub 和 java -jar s
根据WAI-ARIA specification两个角色都应该有: 关注第一个可聚焦元素 用户不能离开对话框 应该设置适当的 aria-label 应该用来中断流程,并且应该要求采取一些行动,例如单击
我想设计一个具有以下要求的数据库,但我遇到了问题。 我有 3 种类型的用户:医生、注册用户和管理员。将来我可能会添加其他类型的用户。这些用户类型中的每一种都有不同的配置文件字段。例如,注册用户应该有
我是 jQuery 和网页设计的新手,请原谅我问这个幼稚的问题。 关于latest jQuery mobile website ,他们的例子是: Page content goes here
我正在查看文档: http://pyqt.sourceforge.net/Docs/PyQt4/qtablewidgetitem.html#data 我可以将行 IDList.append(item.
我看到角色出现一些奇怪的异常,我不知道如何解释。角色名RD........ under ,我能期望它是什么?它是我在该特定服务组中的所有服务都在其上运行的底层机器吗? 最佳答案 Application
我正在尝试使用我的 GitHub 设置 CodeDeploy,但发现了一些问题。 我已使用 AWSCodeDeployRole 策略创建了服务角色,如文档中所述。 在我的 Code Deploy 应用
我正在尝试创建一个 Web 服务并将其部署到 Azure 云服务 场景非常简单:通过 http 或 https 向服务发送请求并接收一些数据。 我无法从文档中判断这是否应该在 WebRole 或 Wo
我从 ASP.NET Identity 的声明授权开始,如果我的应用程序中需要“角色”概念,我想阐明处理它们的方式。 注意:我对这个真的很陌生,所以所有的概念都在我脑海中飞舞,请多多关照,对于任何概念
我知道这个问题与一些类似,但我的设置与那些不同。 EF 中具有以下类的正确配置是什么? 这里的问题是 Team有一个可选的 DivisionParticipant ,但是 DivisionPartic
我无法运行 Windows Azure Hello World 示例。它给了我以下错误: “一个或多个角色启动角色失败”。 我将项目放在 D 驱动器的根目录中,以确保路径长度不是问题。我还清除了 Az
我正在尝试向我的 Xcode 添加一个帐户,但我一直收到此错误。另一个 Xcode 上的相同帐户可以完美运行。我有其他帐户运行良好。 错误是(如标题所述) The role information i
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
在 Bash 脚本中,我想删除 Postgres 用户角色。但是 Postgres 不允许我这样做,我得到了 Cannot drop table X because other objects dep
我目前正在设置一个新项目并创建我的登录系统。由于某种原因,它似乎正在搜索角色表?到目前为止,这是我的结构: Controller public function action_index() {
我有三个模型,一个用户,一个个人资料和一个角色,我试图通过个人资料角色附加到用户强>. # user.rb class User :profiles has_many :users end 我正
我想使用 Spring Security JSP 标签库根据角色有条件地显示一些内容。但是在 Spring Security 3.1.x 中只检查一个角色。 我可以使用,但 ifAllGranted
我是一名优秀的程序员,十分优秀!