I created a custom model for the entity structure and asp.net identifier. I checked the other answers here, they are close to my question, but the answers do not meet my requirements. so I ask here.
Everything is good. But when I try to get the user id, for example:
ApplicationUser user = await manager.FindByIdAsync(User.Identity.GetUserId());
User.Identity.GetUserId () returns a string. I configured it as a guid. But it returns a string: (
My classes are here. Please help me, how can I get User.Identity.GetUserId () in the api web controller as Guid?
public class GuidUserLogin : IdentityUserLogin<Guid> { } public class GuidUserRole : IdentityUserRole<Guid> { } public class GuidUserClaim : IdentityUserClaim<Guid> { } public class GuidRole : IdentityRole<Guid, GuidUserRole> { } //public class GuidUserContext : IdentityDbContext<ApplicationUser, GuidRole, Guid, GuidUserLogin, GuidUserRole, GuidUserClaim> { } public class GuidUserStore : UserStore<ApplicationUser, GuidRole, Guid, GuidUserLogin, GuidUserRole, GuidUserClaim> { public GuidUserStore(DbContext context) : base(context) { } } public class GuidRoleStore : RoleStore<GuidRole, Guid, GuidUserRole> { public GuidRoleStore(DbContext context) : base(context) { } } public class ApplicationUser : IdentityUser<Guid, GuidUserLogin, GuidUserRole, GuidUserClaim>, ICreateDateRequired { public ApplicationUser() { } [Key] public Guid UserId { get; set; } public override Guid Id { get; set; } public override string UserName { get; set; } public string Name { get; set; } public string Surname { get; set; } public string Password { get; set; } //Matching Attributes public override string Email { get; set; } public string FacebookId { get; set; } public string TwitterId { get; set; } public string GoogleId { get; set; } public override string PhoneNumber { get; set; } public string SocialAccessToken { get; set; } public string Gender { get; set; } public virtual List<Shade> Shades { get; set; } [InverseProperty("ParentUser")] public virtual List<UserFriendship> Friends { get; set; } public virtual List<Contact> Contacts { get; set; } //[Column(TypeName = "DateTime2")] //[DatabaseGenerated(DatabaseGeneratedOption.Computed)] public DateTime? CreateDate { get; set; } public string ImageUrl { get; set; } public string ThumbUrl { get; set; } public string BackUrl { get; set; } public virtual List<ContactDetail> UserContactDetails { get; set; } }
source share