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; }