如何删除基本字段并在AspNetCore.Identity上添加自定义字段? [英] How to delete basic fields and add custom fields on AspNetCore.Identity?

查看:67
本文介绍了如何删除基本字段并在AspNetCore.Identity上添加自定义字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

身份 外观的基本结构

Basic structure of Identity looks

using Microsoft.AspNetCore.Identity;
using System;

namespace Microsoft.AspNetCore.Identity
{

    //     Represents a user in the identity system

    //   TKey:
    //     The type used for the primary key for the user.
    public class IdentityUser<TKey> where TKey : IEquatable<TKey>
    {

        //     Initializes a new instance of Microsoft.AspNetCore.Identity.IdentityUser`1.
        public IdentityUser();

        //     Initializes a new instance of Microsoft.AspNetCore.Identity.IdentityUser`1.

        public IdentityUser(string userName);

        //     Gets or sets the date and time, in UTC, when any user lockout ends.
        //     A value in the past means the user is not locked out.
        public virtual DateTimeOffset? LockoutEnd { get; set; }

        //     Gets or sets a flag indicating if two factor authentication is enabled for this
        //     user.
        [PersonalData]
        public virtual bool TwoFactorEnabled { get; set; }

        //     Gets or sets a flag indicating if a user has confirmed their telephone address.
        [PersonalData]
        public virtual bool PhoneNumberConfirmed { get; set; }

        //     Gets or sets a telephone number for the user.
        [ProtectedPersonalData]
        public virtual string PhoneNumber { get; set; }

        //     A random value that must change whenever a user is persisted to the store
        public virtual string ConcurrencyStamp { get; set; }

        //     A random value that must change whenever a users credentials change (password
        //     changed, login removed)
        public virtual string SecurityStamp { get; set; }

        //     Gets or sets a salted and hashed representation of the password for this user.
        public virtual string PasswordHash { get; set; }

        //     Gets or sets a flag indicating if a user has confirmed their email address.
        [PersonalData]
        public virtual bool EmailConfirmed { get; set; }

        //     Gets or sets the normalized email address for this user.
        public virtual string NormalizedEmail { get; set; }

        //     Gets or sets the email address for this user.
        [ProtectedPersonalData]
        public virtual string Email { get; set; }

        //     Gets or sets the normalized user name for this user.
        public virtual string NormalizedUserName { get; set; }

        //     Gets or sets the user name for this user.
        [ProtectedPersonalData]
        public virtual string UserName { get; set; }

        //     Gets or sets the primary key for this user.
        [PersonalData]
        public virtual TKey Id { get; set; }

        //     Gets or sets a flag indicating if the user could be locked out.
        public virtual bool LockoutEnabled { get; set; }

        //     Gets or sets the number of failed login attempts for the current user.
        public virtual int AccessFailedCount { get; set; }

        //     Returns the username for this user.
        public override string ToString();
    }
}

但是我不需要很多字段(例如EmailConfirmed和其他字段).

But I don’t need many fields (like EmailConfirmed and some other).

但是我需要添加一些简单类型的自定义字段( string,int )和一些多对多关系( List )的字段,这些字段与关系用户相同+角色用户-UsersRoles-角色" .

But I need to add some custom fields of simple type (string, int) and some field for many-to-many relationship (List) same as relationship Users + Roles "Users - UsersRoles - Roles".

如何做到这一点而又不会失去功能和充分使用 身份

How can this be done without losing functionality and the ability to fully use Identity

推荐答案

您不能删除任何内置属性.他们在那里支持身份功能.无论您是否实际上需要电子邮件确认,了解电子邮件是否已确认都是很重要的.

You cannot remove any of the built-in properties. They're there to support Identity functionality. Whether or not you're actually requiring email confirmation, it's valuable to know whether the email has been confirmed or not.

添加其他属性就像其他任何实体一样.创建一个从 IdentityUser 继承的类(如果尚未创建),然后向其中添加所需的任何属性.

Adding additional properties works just like any other entity would. Create a class, if you haven't already, that inherits from IdentityUser, and add whatever properties you like to that.

这篇关于如何删除基本字段并在AspNetCore.Identity上添加自定义字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆