1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| public static class CurrentUser { #region Initialize
private static IHttpContextAccessor _httpContextAccessor;
private static ISession _session => _httpContextAccessor.HttpContext.Session;
public static void Configure(IHttpContextAccessor httpContextAccessor) { _httpContextAccessor = httpContextAccessor; }
#endregion
#region Attribute
/// <summary> /// 用户主键 /// </summary> public static string UserOID { get => _session == null ? "" : _session.GetString("CurrentUser_UserOID"); set => _session.SetString("CurrentUser_UserOID", !string.IsNullOrEmpty(value) ? value : ""); }
/// <summary> ///用户编号 /// </summary> public static long UserId { get => _session == null ? 0 : Convert.ToInt64(_session.GetString("CurrentUser_UserId")); set => _session.SetString("CurrentUser_UserId", value != 0 ? value.ToString() : "0"); }
/// <summary> /// 用户姓名 /// </summary> public static string UserName { get => _session == null ? "" : _session.GetString("CurrentUser_UserName"); set => _session.SetString("CurrentUser_UserName", !string.IsNullOrEmpty(value) ? value : ""); }
/// <summary> /// 用户登录账户 /// </summary> public static string UserAccount { get => _session == null ? "" : _session.GetString("CurrentUser_UserAccount"); set => _session.SetString("CurrentUser_UserAccount", !string.IsNullOrEmpty(value) ? value : ""); }
/// <summary> /// 用户头像地址 /// </summary> public static string UserImage { get => _session == null ? "" : _session.GetString("CurrentUser_UserImage"); set => _session.SetString("CurrentUser_UserImage", !string.IsNullOrEmpty(value) ? value : ""); }
/// <summary> /// 用户角色 /// </summary> public static string UserRole { get => _session == null ? "" : _session.GetString("CurrentUser_UserRole"); set => _session.SetString("CurrentUser_UserRole", !string.IsNullOrEmpty(value) ? value : ""); }
/// <summary> /// 主页地址 /// </summary> public static string UserPage { get => _session == null ? "" : _session.GetString("CurrentUser_UserPage"); set => _session.SetString("CurrentUser_UserPage", !string.IsNullOrEmpty(value) ? value : ""); }
#endregion }
|