【发布时间】:2019-02-26 23:07:49
【问题描述】:
我一直在对我的项目进行更改以合并 ASP.Net Identity。 现在我已经停止了一个特定的问题。 我有一个名为 Files 的模型,我必须能够添加只有特定角色的用户才能看到的文件。 假设我添加了一份仅供开发人员、测试人员和管理员使用的报告,但 HumanResources 和 Accounting 不应该看到该条目。
我这样指定我的模型:
public class FileModel
{
[Key]
[Required]
public Guid Id { get; set; }
[Required]
[Display(Name = "File Name")]
[StringLength(50)]
public string Name { get; set; }
[StringLength(280)]
public string Description { get; set; }
[Required]
public string Filetype { get; set; }
[Required]
public string Path { get; set; }
[Required]
[Display(Name = "Allowed Users")]
public virtual List<IdentityRole> Roles { get; set; }
}
我的期望是我能够将角色添加到文件中,但即使我在模型中指定了一个 IdentityRole 列表,当我迁移它时,它从未在数据库中创建来自 FileModel 和角色的映射,并且有在 FileModel 表中没有提到角色。有没有更好的方法来解决这个问题?
【问题讨论】:
标签: asp.net asp.net-mvc asp.net-identity