Last post Aug 12, 2014 04:36 PM by mswhat
Aug 07, 2014 10:32 AM|craigber|LINK
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.
Aug 07, 2014 12:21 PM|march11|LINK
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?
Aug 07, 2014 12:32 PM|craigber|LINK
Database is local install of SQL Server 2014 Developer Edition. I don't have that menu option.
Aug 07, 2014 02:10 PM|march11|LINK
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
Aug 07, 2014 03:33 PM|craigber|LINK
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
It's now working.
Is Startup.cs documented anywhere? I should not have lost two days of work to track this down.
Aug 07, 2014 03:42 PM|march11|LINK
sounds like you just missed copying over some files when you set this up.
Glad you got it.
Sorry I couldn't help more.
Aug 08, 2014 09:33 AM|craigber|LINK
There shouldn't be any copying. Looks like the NuGet package didn't install IndentityConfig.cs.
Aug 08, 2014 12:06 PM|march11|LINK
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."
Aug 12, 2014 04:36 PM|mswhat|LINK
@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?
Did you use the SampleApp controllers and views or make your own?