I looked at Roles.IsUserInRole (string rolename) in a .net reflector and it solves the following:
public static bool IsUserInRole(string roleName) { return IsUserInRole(GetCurrentUserName(), roleName); }
I would look at your current user. That's why:
private static string GetCurrentUserName() { IPrincipal currentUser = GetCurrentUser(); if ((currentUser != null) && (currentUser.Identity != null)) { return currentUser.Identity.Name; } return string.Empty; }
I would argue that this returns an empty string because you either do not have the current user, or his name is an empty string or null.
The IsUserInRole(string username, string roleName) method has the following code block at the beginning of the code:
if (username.Length < 1) { return false; }
If your GetCurrentUserName() does not return anything meaningful, then it will return false before it calls your overridden method.
The moral to clean it: Reflector is a great tool :)
source share