2020-05-11 14:23:27 版本 : 服务网关下层的服务如何获取当前操作者身份信息
作者: 余承浩 于 2020年05月11日 发布在分类 / 人防组 / 人防后端 下,并于 2020年05月11日 编辑
 历史版本

修改日期 修改人 备注
2020-05-21 15:39:15[当前版本] 余承浩 格式调整
2020-05-11 14:23:27 余承浩 创建版本

前置条件

在需要使用操作者信息的项目中 从在公司的nuget类库中 添加包 CommonTools_YCH

具体使用

.net core 提供了 上下文接收的类 HttpContextAccessor

    在Startup中添加依赖注入

            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
在构造函数中通过依赖注入获取 HttpContextAccessor 对象

var user = new UserMsgHelp(_accessor).GetUser();
上述方法即可获取通过网关权限过滤的操作者信息

    public class UserMsg
    {
        public UserMsg ();

        public string Account { get; set; }
        public string AccountId { get; set; }
        public string UserId { get; set; }
        public string UserName { get; set; }
    }

历史版本-目录  [回到顶端]
    知识分享平台 -V 4.8.7 -wcp