IdentityManager / IdentityManager.AspNetIdentity

ASP.NET Identity support for Thinktecture IdentityManager
Apache License 2.0
60 stars 51 forks source link

How to make Roles work with MVC app? #33

Closed rogersbrad closed 8 years ago

rogersbrad commented 8 years ago

Download and Run IdentityManager.AspNetIdentity, but change the web.config so that the database points to an existing 'windows' db that has the asproles, aspuser tables there. It faults out, apparently the formatting is not compatible? Delete existing tables, let it build them with EF. Add users, roles.

Build a new MVC app, setup some model class, setup a controller w/views with EF. set the path to the db as with the aspnetidentity app.

In a controller, setup [Authorize(Roles="PowerAde")]

in the identitymanager app, setup the role of PowerAde and assign it to your user account. here we have active directory

run it, expecting Roles to work in the MVC app, they dont. Any attempt to hit the controller goes to the login screen. Make a new role, assign to a user, save, try again, no, goes to the login screen.

Login appears to interact fine, but Role does not. The documentation does not appear to fully cover how the MVC app has to be configured. Does Web.config have to be altered to contain the definition for a role controller? MVC apps will NOT contain `

      </roleManager>

`

is this required? Following instructions from the web/wiki to the letter, Roles do not work

In a controller, added this var x254367786765 = User.Identity.Name.ToString(); var x339478573 = User.IsInRole("Admin");

it gets the username right. and returns FALSE in the 2nd part. yet I ran this code:

` public static ApplicationRoleManager Create(IdentityFactoryOptions options, IOwinContext context) { var roleStore = new RoleStore(context.Get()); var roleManager = new ApplicationRoleManager(roleStore); if(!roleManager.RoleExists("Admin")) { roleManager.Create(new IdentityRole("Admin")); }

        return new ApplicationRoleManager(roleStore);
    }`

in identityconfig.cs and the first time thru? it added a new role in the IdentityManager database table that i could see from the IM browser page.

NikolayTimofeev commented 8 years ago

@rogersbrad I belive the answer to this question was found at another issue thread