How to customize Asp.net Identity to create a User using my own User Table, like in Webmatrix?

368 Views Asked by At

I'm using Simplemembership provider in asp.net MVC 4, but I'will change to ASp.net MVC 5 using Asp.net Identity. In my code, using Webmatrix, the table Funcionario is used to authenticate:

WebSecurity.CreateUserAndAccount(funcionario.Login, funcionario.Senha, new
{
   Id_Cargo = (short)funcionario.Id_Cargo,
   Confirma_Senha = senhaCriptografada,
   Nome_Usuario = funcionario.Nome_Usuario,
   Senha = senhaCriptografada,
   Id_Distribuidor = funcionario.Id_Distribuidor,
   Login = funcionario.Login,
   Status = 1,
   CPF_Usuario = Util.RemoveNaoNumericos(funcionario.CPF_Usuario),
   Data_Cadastro = DateTime.Now
});

Is there any way to cutomize my user table like in Webmatrix? Using asp.net identity, the table AspNetUser is created to store the system users. How can I do something like that, but using asp.net identity?

1

There are 1 best solutions below

1
Adersh M On

Yes its possible.

Starting from ASP.NET Identity 2.0 , we can extend the default ApplicationUser Class as

class ApplicationUser : IdentityUser 
{
   // Additional properties goes here
}

This ApplicationUser class will have all the basic properties of Identity user and the addition properties. Then in your controller create a property using the ApplicationUser class as

public ApplicationUserManager UserManager
        {
            get
            {
                return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
            }
            private set
            {
                _userManager = value;
            }
        }