Last active
October 26, 2023 17:12
-
-
Save theuntitled/7c70fff994993d7644f12d5bb0dc205f to your computer and use it in GitHub Desktop.
Ignoring "Roles", "Claims" and "Logins" when serializing an ApplicationUser / IdentityUser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ComponentModel.DataAnnotations; | |
using Microsoft.AspNet.Identity.EntityFramework; | |
using Newtonsoft.Json; | |
namespace Project.Models | |
{ | |
[MetadataType(typeof (ApplicationUserMetaData))] | |
public class ApplicationUser : IdentityUser | |
{ | |
// ... | |
#region overrides | |
public override string Email { get; set; } | |
[JsonIgnore] | |
public override bool EmailConfirmed { get; set; } | |
[JsonIgnore] | |
public override bool TwoFactorEnabled { get; set; } | |
[JsonIgnore] | |
public override string PhoneNumber { get; set; } | |
[JsonIgnore] | |
public override bool PhoneNumberConfirmed { get; set; } | |
[JsonIgnore] | |
public override string PasswordHash { get; set; } | |
[JsonIgnore] | |
public override string SecurityStamp { get; set; } | |
[JsonIgnore] | |
public override bool LockoutEnabled { get; set; } | |
[JsonIgnore] | |
public override DateTime? LockoutEndDateUtc { get; set; } | |
[JsonIgnore] | |
public override int AccessFailedCount { get; set; } | |
#endregion | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using Microsoft.AspNet.Identity.EntityFramework; | |
using Newtonsoft.Json; | |
namespace Project.Models | |
{ | |
public class ApplicationUserMetaData | |
{ | |
[JsonIgnore] | |
public ICollection<IdentityUserClaim> Claims { get; } | |
[JsonIgnore] | |
public ICollection<IdentityUserLogin> Logins { get; } | |
[JsonIgnore] | |
public ICollection<IdentityUserRole> Roles { get; } | |
} | |
} |
Thanks for sharing this.
Years go by ... \o/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<3