如何进行多重继承

本文关键字:多重继承 何进行 | 更新日期: 2023-09-27 18:17:49

我是使用asp.net web api的SignlR新手。我想做的是创建一个管理员组。

[OurAuthorization]
    public class NotificationHub : Hub 
    {
        public void Hello()
        {
            Clients.All.hello();
        }
        public override Task OnConnected()
        {
            //if the user is admin add him to the group.which i can access if i have base controller.
            Groups.Add(Context.ConnectionId, "Admins");
            return base.OnConnected();
        }
        public override Task OnDisconnected(bool stopCalled)
        {
            Groups.Remove(Context.ConnectionId, "Admins");
            return base.OnDisconnected(stopCalled);
        }
    }

问题是我不能访问当前用户状态(admin或普通用户)没有基本控制器。我现在不能让NotificationHub从控制器继承任何其他的想法,我如何实现它。她是基础控制器。

public class BaseController : ApiController
    {
        public OurIdentity CurrentUser
        {
            get
            {
                OurIdentity identity = new OurIdentity();
                if (Thread.CurrentPrincipal.Identity is OurIdentity)
                {
                    identity = Thread.CurrentPrincipal.Identity as OurIdentity;
                }
                return identity;
            }
        }
        protected override void Initialize(HttpControllerContext controllerContext)
        {
            if (Thread.CurrentPrincipal.Identity is OurIdentity)
            {
                OurIdentity identity = Thread.CurrentPrincipal.Identity as OurIdentity;
            }
            base.Initialize(controllerContext);
        }
    }

我正在使用自定义令牌授权

如何进行多重继承

在Hub中,您可以通过

获得Identity
Context.User.Identity