简体   繁体   中英

Use my custom user in asp mvc 5 application

I want use my own User rather than using the ApplicationUser provided by the .Net framework.

In my Register method i have :

public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.UserName, };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                }
                else
                {
                    AddErrors(result);
                }
            }

Is there any way to use a custom user class instead of using the default user application even if I know that we can add some properties for the default UserAplication.

some thing like :

var user = new MyUser() { UserName = model.UserName, LastName = "LastName "};
var result = await UserManager.CreateAsync(user, model.Password);

Thanks in advance

Maybe not the prettiest of solutions, but..

Remove the ApplicationUser class from the MVC project, compile. Where you get compile errors, replace the reference to the ApplicationUser class with your MyUser class.

And remember, MyUser has to inherit from the IdentityUser class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM