Your article is very useful for beginners of ASP.NET MVC5.
For me i was actually looking how asp.net identity creates database and how we can extend it to our needs, you rocked it. i got my answer thank you very much.
Hi Jhon, how can I access to current user new fields in the controller?
I would like to do something like this: "User.Birthdate" from my controller action but I only can get "ser.Identity.GetUserId()".
I know I could create a Linq function to search for It, but I dont want to do that in my controller since I have a DataAccess layer.
Excellent work, I followed the tutorial and everything looks good, but when I tried to verify if a user has a role I get always false.
The role is created in DB and also is assigned to the user in AspnetUserRoles table.
I have two databases and Connection strings are both ok.
Did I need to configure anything else?
What version of visual studio are you using, and which version of MVC/Identity?
This article was written against Identity 1.0 in VS 2012, and there have been several updates since then. Not certain what's going on in your code without seeing it, but some of what I did in this article may have changed with the updates.
Thanks for the great tutorial. I have worked through a few around this topic however they don't seem to cover a situation I thought would be common.
I would like to make use of an existing database in a new project. In my first attempt I created a new project and followed your tutorial. I then added a new Data Model using "Code First from Existing Database". This created a new context so at this stage I was looking at two contexts each with there own database.
I enabled the migrations in separate folders using -MigrationsDirectory. The project worked locally however when I tried to publish (creating two separate databases with their won connection strings) one the IdentityModel database was created.
I have tried a number of options including trying to merge the tables into one database but I am having no you.
Could you please provide some tips or point me in the direction of a tutorial that deals with this specific issue.
I followed everything on your tutorial and it works fined when I ran it on the visual studio but when I deployed it on IIS I got a problem. It says that "Migrations is enabled for context 'ApplicationDbContext' but the database does not exist or contains no mapped tables. Use Migrations to create the database and its tables, for example by running the 'Update-Database' command from the Package Manager Console."
Thanks for this tutorial. Its been very useful in getting me setup with a website with multiple roles. I have another requirement which I cannot figure out.How do you place an sliding sign out feature with this design.
Yeah, just create the models in the same context. Code-first can only use one context, as I understand things. So, just point all of them at ApplicationDbContext, and all your models will be build in one Db instead of two.
I've been in the same situation, resolved by enabling migration for the identity context, specifying a different migrations directory:
it did create all the migrations stuff in a separate folder in the project, and from that point everything works as indicated.
I'm at the early stage of development of my project... and I do believe that the testing will be easier if I drop / re-create my db every time load my project. (using DropCreateDatabaseAlways in my seed)
The problem is that "users management" tables are only created after registering the first user (AccountController/Register)... and I cant figure out how to call that function from my seed...
Not sure if it's the correct approach if I want to create users with missing tables?
Thanks so much for this. Really helpful - but you stop one step short!!
I have searched and searched but I cannot find an example of how to add the extended info to the Manage view so users can update their info. Not necessarily their user name, but their email address and home address (the new fields I have added)..
Is there a walk through of this process anywhere online? Thanks for your great info! Keep it coming!
I haven't given up, but I guess I am more concerned about "best practice" and using the Identity to its full potential CORRECTLY!
I read the following article and wondered if I should create an Edit View rather than try to use Manage, but my gut tells me that since I'm not assigning roles I should stick with Manage and keep the password management on the same screen as the other user info, so all could be updated..
I'm sure there are lots of way to approach it, but I want to use the most efficient methods. And your advice is the best I've found!
It will all depend on what you want to accomplish. Do you want each user to be able to change their basic info (Email, phone, etc)? Or do you want only the admin to be able to do that?
Note that changing th username, under the current design, is not a good idea.
I will see what I can come up with, and let you know. It's not hard (I've done it on a different project), but I want to make sure to pass on the best info, not just what I recall off the top of my head.
Last Visit: 31-Dec-99 19:00 Last Update: 2-Mar-24 20:06