ASP.NET Identity remove column from AspNetUsers table

后端 未结 5 782
轻奢々
轻奢々 2021-01-31 21:12

When I use ASP.NET Identity first code approach, I want to generate columns in AspNetUsers table in my own way. I don\'t need to have stored multiple columns with null values. I

5条回答
  •  隐瞒了意图╮
    2021-01-31 21:30

    I know this might not be completely related, but if you simply want to exclude columns in JSON responses all you have to do is place [JsonIgnore] above the property. I use Entity so by default the (encrypted) password is included in the model. Even if the password is encrypted you still don't want the end-user to get it. One way to maintain access to that property without including it in a response is shown below.

    In the below example the Password field would be removed from the Json response because we added [JsonIgnore] to the model.

    public int Id { get; set; }
    public string Email { get; set; }
    
    [JsonIgnore]
    public string Password { get; set; } // <--- Removed from JSON response
    
    public string FirstName { get; set; }
    public string MiddleName { get; set; }
    public string LastName { get; set; }
    public string PhoneNumber { get; set; }
    public bool Active { get; set; }
    

    Here is a sample JSON response.

    {
      "id": 1,
      "email": "ddavis@example.com",
      "firstName": "Daniel",
      "middleName": "Cool-Guy",
      "lastName": "Davis",
      "phoneNumber": "12055550000",
      "active": true
    }
    

提交回复
热议问题