0

i need to prepare an MVC 5 application with an existing tbl_users table for members. Can i use or modify Asp.Identity or need to prepare a custom membership? Please advise.

CREATE TABLE [dbo].[tbl_user](
    [id] [bigint] IDENTITY(1,1) NOT NULL,
    [user] [varchar](50) NOT NULL,
    [password] [varchar](60) NOT NULL,
    [password_raw] [varchar](255) NULL,
    [name] [varchar](255) NOT NULL,
    [email] [varchar](255) NOT NULL,
    [url] [varchar](255) NULL,
    [language] [varchar](255) NULL,
    [active] [smallint] NOT NULL,
    [session_id] [varchar](100) NULL,
    [reg_date] [datetime2](0) NOT NULL,
    [theme] [varchar](255) NULL,
    [timezone] [varchar](255) NULL,
    [last_visit_date] [datetime2](0) NULL,
    [past_visit_date] [datetime2](0) NULL,
    [activation] [varchar](32) NULL,
    [activation_date] [datetime2](0) NULL,
    [ip_address] [varchar](255) NULL,
    [security_question] [varchar](255) NULL,
    [security_answer] [varchar](255) NULL,
    [lock_url] [varchar](500) NULL,
    [lock_is_locked] [smallint] NOT NULL,
    [lock_time] [datetime2](0) NULL,
    [change_password] [smallint] NOT NULL,
    [last_change_password_date] [datetime2](0) NOT NULL,
    [expire_date] [date] NULL,
    [employee_no] [bigint] NULL,
    [student_no] [bigint] NULL,
    [parent_no] [bigint] NULL,
    [user_type] [varchar](5) NULL,
    [last_site] [varchar](50) NULL

Thank you.

1 Answer 1

2

You could derive your custom user class from IUser and define properties (extras) there. Something like this:

public class IdentityUser: IUser
{
    #region Constructors

    /// <summary>
    /// Initializes a new instance of the <see cref="IdentityUser"/> class
    /// </summary>
    public IdentityUser()
    {
        Id = Guid.NewGuid().ToString();
        Roles = (ICollection<IdentityUserRole>)new List<IdentityUserRole>();
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="IdentityUser"/> class
    /// </summary>
    /// <param name="username">Username for the user</param>
    public IdentityUser(string username): this()
    {
        UserName = username;
    }

    #endregion

    #region IUser<string> members
    // Custom properties...
    #endregion
}

You can find more information here: https://jinishbhardwaj.wordpress.com/2014/07/16/decoupling-asp-net-identity-2-0-from-entity-framework-in-mvc5-part-1/

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the help; i am working on it: protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.AddFromAssembly(typeof(IdentityModel.Configurations.IdentityUserConfiguration).Assembly); } IdentityModel is causing problem, couldnt be found, using Microsoft.AspNet.Identity; is also added.
IdentityModel is the name of the assembly. It seems that your IdentityUserConfigur‌​ation.cs file is defined in the IdentityModel assembly in the IdentityModel.Configurations namespace. You need to import that assembly in your project. Or correct the namespace in your OnModelCreating method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.