/// <summary> /// Gets a value indicating whether the specified user is in the specified role for the configured applicationName. /// </summary> /// <param name="username">The user name to search for.</param> /// <param name="roleName">The role to search in.</param> /// <returns>true if the specified user is in the specified role for the configured applicationName; otherwise, false.</returns> public override bool IsUserInRole(string username, string roleName) { try { using (InventoryManagementEntities context = new InventoryManagementEntities()) { if (!EFMembershipProvider.CheckUser(username, ApplicationName, context)) { return(false); } return((from u in context.aspnet_Membership where u.aspnet_Users.UserName == username && u.aspnet_Applications.ApplicationName == ApplicationName from r in u.aspnet_Users.aspnet_Roles where r.RoleName == roleName && r.aspnet_Applications.ApplicationName == ApplicationName select r).Count() > 0); } } catch (Exception ex) { if (WriteExceptionsToEventLog) { WriteToEventLog(ex, "IsUserInRole"); } throw; } }
/// <summary> /// Gets a list of the roles that a specified user is in for the configured applicationName. /// </summary> /// <param name="username">The user to return a list of roles for.</param> /// <returns>A string array containing the names of all the roles that the specified user is in for the configured applicationName.</returns> public override string[] GetRolesForUser(string username) { using (InventoryManagementEntities context = new InventoryManagementEntities()) { if (!EFMembershipProvider.CheckUser(username, ApplicationName, context)) { throw new ArgumentNullException("username"); } return((from u in context.aspnet_Membership where u.aspnet_Users.UserName == username && u.aspnet_Applications.ApplicationName == ApplicationName from r in u.aspnet_Users.aspnet_Roles where r.aspnet_Applications.ApplicationName == ApplicationName select r.RoleName).ToArray()); } }