2014年6月4日 星期三

Microsoft.AspNet.Identity in MVC 5

Microsoft.AspNet.Identity.Core

image

image

 

Microsoft.AspNet.Identity.EntityFramework

image

image

 

AccountController.cs

new UserManager<ApplicationUser>(…)

image

 

IdentityModel.cs

class ApplicationUser and ApplicationDbContext

image

 

1. Add customize field, FavoriteBook, into IdentityUser table

2. Add customize table, Movie, into IdentityDbContext

image

3. Don’t forget to add textbox of customize field on related Views

4. Don’t forget to do DB Migration to apply schema changes in database, otherwise we will see following error

image

Configuration.cs in Migration folder

5. new ApplicationUser{}

6. new PasswordHasher()

image

7. Or the other way to create default user in Seed method

image

8. Run command, update-database, in Package Manager Console

image

9. If want to add default Role to defaut user

image

沒有留言:

張貼留言