0

I have created a custom Role provider with the following overridden method:

public override string[] GetRolesForUser(string username)
    {
        MyAppUser user = userRepository.Get(u => u.Username == username).FirstOrDefault();
        //MyAppUser user = userRepository.Get(u => u.Username == "testuser").FirstOrDefault();
        if (user == null)
        {
            string[] roles = new string[1];
            roles[0] = "Fail";
            return roles;
        }
        else
        {
            Role role = roleRepository.Get(r => r.RoleID == user.RoleID).FirstOrDefault();
            if (role == null)
            {
                string[] roles = new string[1];
                roles[0] = "Fail";
                return roles;
            }
            else
            {
                string[] roles = new string[1];
                roles[0] = role.Name;
                return roles;
            }
        }

    }

Upon clicking on a section of the site that is authorized only to Admin I am successfully hitting the above method when passing in the username directly "testuser" but otherwise my username parameter is always blank. Where is this parameter populated? And how can I have it so that my current signed in user is checked here, I have a class called MyAppUser that holds user details but authentication is done outside of the app by ADFS and so we have no authentication inside of the project.

Jay
  • 3,012
  • 14
  • 48
  • 99

1 Answers1

0

Where is this parameter populated?

Normally GetRolesForUser method is called from client code (code that you write in your application), so onus is on you to pass username. UserName is normally the login user name that user has used to login into your system so you should have it.

In case you want to discover it programmatically, you might be able to use

System.Web.HttpContext.Current.User.Identity.Name

in ASP.NET MVC.

SBirthare
  • 5,117
  • 4
  • 34
  • 59