locked
ASP.Net Identity 2.0 Role Manager issues RRS feed

  • Question

  • User1937420497 posted

    I have an ASP.Net MVC 5 application using local accounts. I'm now trying to get roles working, but having no luck. Document on this is...I'll just say, not good. I've installed the Identity sample application in its own solution and copy and pasted code to IdenityConfig.cs and into the AccountController.cs. My first step is just to get a list of roles, but RoleManager is always null.

    I've been fighting this for two days now and am getting no where. I'm not sure where to look next. So, I'm seeking advice on how to get this working. Note that user authentication/creation/etc is working fine.

    Thursday, August 7, 2014 10:32 AM

Answers

  • User1937420497 posted

    No, it's not in app_data. User security works fine. Solution compiles so all references are there.

    But...your post along with working on something else a bit prompted me to poke at this a bit more and I found the issue. There is a Startup.cs in the root folder. It calls ConfigureAuth. I traced that to Startup.Auth.cs in the App_Start folder. That file was missing

    app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
    

    It's now working.

    Is Startup.cs documented anywhere? I should not have lost two days of work to track this down.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 7, 2014 3:33 PM

All replies

  • User-359936451 posted

    Not good with MVC but where is your database located? If this is a web site have you used the Web Site Configuration Tool under the website drop down menu in VS?

    Thursday, August 7, 2014 12:21 PM
  • User1937420497 posted

    Database is local install of SQL Server 2014 Developer Edition. I don't have that menu option.

    Thursday, August 7, 2014 12:32 PM
  • User-359936451 posted

    Does it reside in your project, in the app_data folder?

    Can you access all of the membership tables. Do you have all of the correct Identity references to access the membership repository?

    Just some brainstorming

    Thursday, August 7, 2014 2:10 PM
  • User1937420497 posted

    No, it's not in app_data. User security works fine. Solution compiles so all references are there.

    But...your post along with working on something else a bit prompted me to poke at this a bit more and I found the issue. There is a Startup.cs in the root folder. It calls ConfigureAuth. I traced that to Startup.Auth.cs in the App_Start folder. That file was missing

    app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
    

    It's now working.

    Is Startup.cs documented anywhere? I should not have lost two days of work to track this down.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 7, 2014 3:33 PM
  • User-359936451 posted

    sounds like you just missed copying over some files when you set this up.

    Glad you got it.

    Sorry I couldn't help more.

    Thursday, August 7, 2014 3:42 PM
  • User1937420497 posted

    There shouldn't be any copying. Looks like the NuGet package didn't install IndentityConfig.cs.

    Friday, August 8, 2014 9:33 AM
  • User-359936451 posted

    Ah NuGet, but I was referring to how you stated you set this up....

        "  in its own solution and copy and pasted code to IdenityConfig.cs and into the AccountController.cs."

    Friday, August 8, 2014 12:06 PM
  • User-1900345072 posted

    @craigber...I am having a similar problem and would love more details on your solution.  I'm working on an MVC 5 app using local accounts (Identity 2.0) and have modified the Application User to contain more fields (first name, last name, company, etc). 

    I need to add a role and then apply it to a user but am having a heck of time figuring out how to get it done with ID 2.0. 

    I like the way the Identity Sample app handles roles and user/role mappings but I do NOT want to use that sample app as a base because I can't figure a way around the email verify (my users are set locally and I don't need the email verify).

    So did I understand correctly that you just copy the pertinent code from the sample app IdentityConfig.cs and then added the sample controllers and views?  And the line below in Startup.Auth.cs?

    app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);

    Did you use the SampleApp controllers and views or make your own?

    Thanks,

    ~Mike

    Tuesday, August 12, 2014 4:36 PM