1

So i'm trying to build off Identitie's individual authentication system but every check I do for a Role of the User returns with false, here is my controller for logging in which I would redirect the user if I could do a role check.

var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
        switch (result)
        {
            case SignInStatus.Success:
                var r = Roles.IsUserInRole( "Trainer");
                var y = User.IsInRole("Trainer");
                return RedirectToAction("index", "Home");

Every time i've run this both of these methods(vars r and y) return false. I have enabled RoleManager with
<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"/>
And I for sure have a Role "Trainer" since I run this to make a test user await UserManager.AddToRoleAsync(user.Id, "Trainer");

Toxicable
  • 1,639
  • 2
  • 21
  • 29

1 Answers1

0

It looks like you mix Microsoft.AspNet.Identity with System.Web.Security which is not working as expected.

I can't actually try it right now, but using the UserManager should work better. Something like

SignInManager.UserManager.IsInRoleAsync(model.Email, "Trainer");

See this SO answer for more information

Community
  • 1
  • 1
grek40
  • 13,113
  • 1
  • 24
  • 50
  • Yeah I wasn't trying to use both methods, was just trying each one to see if one would work, however UserManager did it for me, thanks – Toxicable Jan 06 '16 at 08:53