Results 1 to 2 of 2

Thread: Difficulties Trimming Down Identity

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    10,440

    Difficulties Trimming Down Identity

    I've tried trimming down the identity classes like an idiot and now I can't hit the database without database operation failures, specifically unknown columns.

    This is what my schema definition looks like:
    Code:
    using Microsoft.AspNetCore.Identity;
    using System;
    using System.ComponentModel.DataAnnotations.Schema;
    
    namespace ProjectName.Data
    {
        namespace Schema
        {
            public class AspNetRoles : IdentityRole
            {
                public string Slug { get; set; }
                public string Description { get; set; }
                public int SortOrder { get; set; }
                public Guid? CreatedBy { get; set; }
                public DateTime? CreatedOn { get; set; }
                public Guid? ModifiedBy { get; set; }
                public DateTime? ModifiedOn { get; set; }
                public DateTime? DeletedOn { get; set; }
                [NotMapped] public override string NormalizedName { get; set; }
                [NotMapped] public override string ConcurrencyStamp { get; set; }
            }
    
            public class AspNetUserRoles
            {
                public Guid AspNetUserRoleId { get; set; }
                public Guid AspNetUserId { get; set; }
                public Guid AspNetRoleId { get; set; }
            }
    
            public class AspNetUsers : IdentityUser
            {
                public string FirstName { get; set; }
                public string LastName { get; set; }
                [NotMapped] public override bool TwoFactorEnabled { get; set; }
                [NotMapped] public override bool PhoneNumberConfirmed { get; set; }
                [NotMapped] public override string ConcurrencyStamp { get; set; }
                [NotMapped] public override string NormalizedEmail { get; set; }
                [NotMapped] public override string NormalizedUserName { get; set; }
            }
        }
    }
    And my configuration services looks like this:
    Code:
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseMySql(
                Configuration.GetConnectionString("DefaultConnection")));
        services.AddIdentity<AspNetUsers, AspNetRoles>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultUI()
            .AddDefaultTokenProviders();
        services.AddControllersWithViews();
        services.AddRazorPages().AddMvcOptions(options => options.EnableEndpointRouting = false);
    
        // configure the session
        services.AddSession(options =>
        {
            options.Cookie.HttpOnly = true;
        });
    
        // configure the identity options
        services.Configure<IdentityOptions>(options =>
        {
            // password settings
            options.Password.RequireDigit = true;
            options.Password.RequireLowercase = true;
            options.Password.RequireNonAlphanumeric = true;
            options.Password.RequireUppercase = true;
            options.Password.RequiredLength = 8;
            options.Password.RequiredUniqueChars = 1;
    
            // lockout settings
            options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(15);
            options.Lockout.MaxFailedAccessAttempts = 5;
            options.Lockout.AllowedForNewUsers = false;
    
            // user settings
            options.User.AllowedUserNameCharacters =
            "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
            options.User.RequireUniqueEmail = true;
        });
    
        // configure the cookie options
        services.ConfigureApplicationCookie(options =>
        {
            options.Cookie.HttpOnly = true;
            options.ExpireTimeSpan = TimeSpan.FromHours(1);
    
            options.LoginPath = "/Account/Login";
            options.AccessDeniedPath = "/Identity/Account/AccessDenied";
            options.SlidingExpiration = true;
        });
    
        // configure the auth controller
        services.AddAuthorization(options =>
        {
            options.AddPolicy("Authorized", policy => policy.Requirements.Add(new AuthController()));
        });
        services.AddSingleton<IAuthorizationHandler, LoggedIn>();
    }
    I thought that the [NotMapped] attributes would prevent the user manager from including those fields.

    What am I missing?
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    10,440

    Re: Difficulties Trimming Down Identity

    Unapologetic bump.
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width