From 045ffc8ce2c71ea47674209668a274c6de9e0a75 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 24 Aug 2019 00:08:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=A8=E6=88=B7=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=97=B6=E7=9B=B4=E6=8E=A5=E8=BF=94=E5=9B=9E=E7=A9=BA=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E9=9B=86=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.DataAccess.MongoDB/Role.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Bootstrap.DataAccess.MongoDB/Role.cs b/Bootstrap.DataAccess.MongoDB/Role.cs index 667dfa3c..155fb66c 100644 --- a/Bootstrap.DataAccess.MongoDB/Role.cs +++ b/Bootstrap.DataAccess.MongoDB/Role.cs @@ -78,10 +78,12 @@ namespace Bootstrap.DataAccess.MongoDB { var roles = new List(); var user = UserHelper.Retrieves().Cast().FirstOrDefault(u => u.UserName.ToLowerInvariant() == userName.ToLowerInvariant()); - var role = RoleHelper.Retrieves(); - - roles.AddRange(role.Where(r => user.Roles.Any(rl => rl == r.Id)).Select(r => r.RoleName)); - if (roles.Count == 0) roles.Add("Default"); + if (user != null) + { + var role = RoleHelper.Retrieves(); + roles.AddRange(role.Where(r => user.Roles.Any(rl => rl == r.Id)).Select(r => r.RoleName)); + if (roles.Count == 0) roles.Add("Default"); + } return roles; }