예제 #1
0
 // Inherited from RoleProvider ==> Forwarded to previous provider if this provider hasn't been initialized
 public override bool IsUserInRole(string username, string roleName)
 {
     if (!InitializeCalled)
     {
         return(PreviousProvider.IsUserInRole(username, roleName));
     }
     using (var db = ConnectToDatabase())
     {
         var count = db.QuerySingle(
             "SELECT COUNT(*) FROM "
             + SafeUserTableName
             + " u, "
             + UsersInRoleTableName
             + " ur, "
             + RoleTableName
             + " r Where (u."
             + SafeUserNameColumn
             + " = @0 and r.RoleName = @1 and ur.RoleId = r.RoleId and ur.UserId = u."
             + SafeUserIdColumn
             + ")",
             username,
             roleName
             );
         return(count[0] == 1);
     }
 }
예제 #2
0
 /// <summary>
 /// Gets a value indicating whether the specified user is in the specified role for the configured applicationName.
 /// </summary>
 /// <remarks>Inherited from RoleProvider ==> Forwarded to previous provider if this provider hasn't been initialized</remarks>
 /// <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)
 {
     if ((_previousProvider != null) && !InitializeCalled)
     {
         return(PreviousProvider.IsUserInRole(username, roleName));
     }
     using (var db = NewMySqlSecurityDbContext)
     {
         var count = db.UsersInRoles.Count(x => x.UserProfile.UserName.Equals(username, StringComparison.CurrentCultureIgnoreCase) && x.Role.RoleName == roleName);
         return(count == 1);
     }
 }
        /// <summary>
        /// Gets a value indicating whether the specified user is in the specified role for the configured applicationName.
        /// </summary>
        /// <remarks>Inherited from RoleProvider ==> Forwarded to previous provider if this provider hasn't been initialized</remarks>
        /// <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)
        {
            if (!InitializeCalled)
            {
                return(PreviousProvider.IsUserInRole(username, roleName));
            }
            using (var db = NewMySqlMembershipContext)
            {
                var count = db.UsersInRoles.Count(x => x.UserProfile.UserName == username && x.Role.RoleName == roleName);

                return(count == 1);
            }
        }