Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8538369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:06:40+00:00 2026-06-11T11:06:40+00:00

I faced with new ASP MVC 4 feature, it shipped with new membership db

  • 0

I faced with new ASP MVC 4 feature, it shipped with new membership db schema and new initialization. In mvc 3 and old versions developer able to create custom user profile fields using specifications in web.config, but now i faced with method in filters namespace in default mvc 4 project:

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

and user profile table:

[Table("UserProfile")]
    public class UserProfile
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int UserId { get; set; }
        public string UserName { get; set; }
    }

But the method InitializeDatabaseConnection generate only UserName and UserId i need to generate other additional fields.

I have good experience in EF codeFirst approach, and in that case i try to edit UserProfile Class:

[Table("UserProfile")]
    public class UserProfile
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int UserId { get; set; }
        [Column]
        [Required]
        public string UserName { get; set; }
        [Column]
        [Required]
        public string FirstName { get; set; }
        [Column]
        [Required]
        public string LastName { get; set; }
    }

But when i regenerate database, i havent see any changes, Custom Db fields not generated.
Help me please, how can i create custom user fields?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:06:40+00:00Added an answer on June 11, 2026 at 11:06 am

    Elaborating from the answer above

    The WebSecurity.InitializeDatabaseConnection Method help states that

    If you want to use a database table that contains user profile information (user names, email addresses, and so on), you specify a connection string and table name that the membership system uses to connect to that information. If you do not want to use an existing user profile table, you can specify that the InitializeDatabaseConnection() method should automatically create the user profile table. (A database for the user profile table must already exist.)

    So if we want more fields into the UserProfile table we just need to make sure we are creating a profile table and run the InitializeDatabaseConnection method after the table is already in place.

    In the standard MVC4.0 project template from VS2012 I’ve commented out the Account controller

    [Authorize]
    //[InitializeSimpleMembership]
    public class AccountController : Controller
    {
    

    and moved InitializeDatabaseConnection into the EF Code First Database Initializer

    public class MyDatabaseInit: DropCreateDatabaseAlways<MyDatabaseContext>
    {
        protected override void Seed(MyDatabaseContext context)
        {
            SeedMembership();
        }
    
        private void SeedMembership()
        {
            WebSecurity.InitializeDatabaseConnection("MyDatabaseContext",
                "UserProfile", "UserId", "UserName", autoCreateTables: true);
        } 
    }
    

    ensuring that the InitializeDatabaseConnection runs once the table is already in place.

    Added the UserProfile class to my EF Code First model

    public class MyDatabaseContext : DbContext
    {
        public DbSet<UserProfile> UserProfiles { get; set; }
    
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }
    }
    

    Added the extra field in the UserProfile table

    [Table("UserProfile")]
    public class UserProfile
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int UserId { get; set; }
        public string UserName { get; set; }
        public string MobilePhone { get; set; }
    }
    

    All you need now is to set the database initialization strategy when the application starts and also call a query on the database the make sure it gets created at that point, before any authorization/authentication code is called.

    protected void Application_Start()
    {
       AreaRegistration.RegisterAllAreas();
    
       WebApiConfig.Register(GlobalConfiguration.Configuration);
       FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
       RouteConfig.RegisterRoutes(RouteTable.Routes);
       BundleConfig.RegisterBundles(BundleTable.Bundles);
       AuthConfig.RegisterAuth();
    
       Database.SetInitializer<MyDatabaseContext>(new MyDatabaseInit());
       new MyDatabaseContext().UserProfile.Find(1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As I am new to asp.net mvc I would like to get the list
I am working on a test application based on ASP.NET MVC. I am new
I remember when ASP.NET MVC was new, there was a lot of contention over
I am a new ASP.NET developer and I am facing a problem with inserting
I'm new to ASP.NET MVC so this may be a stupid question. I have
I'm faced a new problem something with memory allocation and leak here is my
I'm new in developing iOS app. So I've recently faced a problem with localization
Hi i am almost new in programing. I am faced with an error that
i am facing a new situation. I know someone definitely had faced these type
I've faced some troubles with context in EF in ASP.MVC2. I thought that best

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.