最新兼容 Asp.Net 身份

Latest Compatible Asp.Net Identity

我可以在非核心 .Net 中使用的最新 ASP.Net 标识版本是什么?

我正在尝试实施基于角色的声明,我看到了代码片段:

roleManager.AddClaimAsync(...

我做了一些研究,发现 "add Claims directly for Roles" 是 ASP.Net Identity Core 的新功能...

目前,我正在使用 ASP.Net Identity 2.x(对于 .Net 4.6)。我有一些选择吗? .Net Core 的 Identity Core 需求?

最新 non-Core 身份是 2.2.1,源代码在 Codeplex 上找到。

如果您需要向角色添加声明,您必须自己实现 - 这并不难:您需要添加一个 table 来保存声明,但引用角色而不是用户 - 请参阅现有的 UserClaims table.

然后当用户登录时,您必须读取所有用户角色及其所有声明并将它们添加到 GenerateUserIdentityAsync 中,就像这样 sample.

请记住,声明在 SecurityStampValidator (sample) 中会被覆盖,因此您确实需要在该方法中向 cookie 添加声明,否则当身份重新生成。