【问题标题】:unable to Inherit from System.Security.Claims.ClaimsPrincipal无法从 System.Security.Claims.ClaimsPrincipal 继承
【发布时间】:2013-07-13 05:48:34
【问题描述】:

MVC5 控制器有一个用户属性,它是 System.Security.Claims.ClaimsPrincipal

我创建了一个从中继承的基本控制器。这个基本控制器的User 属性被mycustomPrinciple 覆盖,它继承自System.Security.Claims.ClaimsPrincipal

 public abstract partial class BaseController : Controller
    {

        public new mycustomPrinciple User
        {
            get
            {
                return base.User as mycustomPrinciple;  //returns null here
            }
        }
     }

public class mycustomPrinciple : System.Security.Claims.ClaimsPrincipal
    {
        private int _ID;

        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

    }

正如你在上面看到的,它在演员阵容中失败了。我不确定为什么这是因为我在 MVC4 中做了类似的事情,但继承的原则是 System.Security.Principal.IPrincipal,因为这是控制器用户属性的一种类型。

【问题讨论】:

    标签: wif claims-based-identity asp.net-mvc-5


    【解决方案1】:

    您错过了 ClaimsPrincipal 的要点 - Claims 集合是您保存应用特定身份数据的地方。然后我建议添加扩展方法来提取特定声明,例如您的“ID”。

    【讨论】:

    • 因此,一旦有人使用其中一种方法登录,您就可以将声明添加到带有 id 的集合中,以允许您识别数据库中的用户,并为声明原则提供扩展方法类,以便您可以将其拉出,或者数据库用户记录?
    • 是的。您可以在称为“声明身份验证管理器”的 WIF 扩展点中执行此操作(我们更喜欢将其称为声明转换器)。
    • 我对这个和stackoverflow.com/questions/17641956/… 中类似查询的一些答案感到困惑。我想当它 RTM 的时候会有更多的细节出来,但是关于 MVC5 中新的声明/身份系统的定制的细节很少
    猜你喜欢
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 2016-03-04
    • 2011-12-07
    相关资源
    最近更新 更多