How to extend asp.net web api 2 user?

I create a project Web API (2)and use "individual account" authentication. I want

  • expand the user with some information (for example, name / surname, etc.) (in model)
  • get this information after login (on the client side - my phone with windows)

I just started studying MVCand Web APIso can anyone help me with this?

Let me explain a bit: I am creating a webapi project and have been selected as the authentication method - "inidividual accounts" I have added a Person model class with two fields: FirstName and LastName. Well, I used a violinist to register a user named "johndoe" with a password. After that, I used fiddler to authenticate this user to "server: port / Token" and got a bearer token. Well here is the problem, I need to know how to associate this custom class with my Person class in the model, and secondly, I do not know how to write a controller, so when you send a request for receipt, our controller function will return the associated Person.

+4
source share
1

, : Identity ASP.NET

ASP.NET Identity . ASP.NET Entity Framework Code .

IdentityUser AspNetUsers , , , , :

public class CustomUser : IdentityUser
{
    public string Email { get; set; }
}

UserManager CustomUser IdentityUser Class, Startup.cs UserManager UserStore:

UserManagerFactory = () => new UserManager<CustomUser>(new UserStore<CustomUser>());

:

public static Func<UserManager<CustomUser>> UserManagerFactory { get; set; }

ApplicationOAuthProvider.cs UserManager CustomUser IdentityUser. " " RegisterBindingModel :

public class RegisterBindingModel
{
    [Required]
    [Display(Name = "User name")]
    public string UserName { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm password")]
    [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }

    public string Email { get; set; }
}

:

 CustomUser user = new CustomUser
        {
            UserName = model.UserName,
            Email=model.Email
        };

,

UPDATE

- ExceptionMessage " " ". , " AspNetUsers " , " ", , , - , AspNetUsers, nvarchar (128) ( , , , " " ), "", ( , CustomUser).

+11

All Articles