I've implemented a custom RoleProvider for a project. The RoleProvider works, but the repository I use to fetch the user roles is only populated after build. When I logOff, change the role of the user, logOn again, the user still holds the old roles.
public class CmsRoleProvider : RoleProvider
{
private EntityDB _db { get; set; }
public CmsRoleProvider()
{
_db = new EntityDB();
}
public override string[] GetRolesForUser(string username)
{
var user = _db.Users.Where(u => u.EmailAddress == username).SingleOrDefault();
var roles = user.UserRoles.Select(u => u.Role.Name).ToList<string>();
return roles.ToArray();
}
}
In the sample above, the user only get the correct roles after building the project. When I create the repository inside the GetRolesForUser function, it works fine.
Is there a caching problem going on? Who can help me with this.