Quantcast
Channel: VBForums - MVC .Net
Viewing all articles
Browse latest Browse all 187

VS 2017 Difficulties Trimming Down Identity

$
0
0
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?

Viewing all articles
Browse latest Browse all 187

Latest Images

Trending Articles





Latest Images