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 9242207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:32:07+00:00 2026-06-18T08:32:07+00:00

How can I integrate EF 5.0 with membership provider using code first? I have

  • 0

How can I integrate EF 5.0 with membership provider using code first?

I have my own database schema which I want to use for registration of users etc.

  • 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-18T08:32:08+00:00Added an answer on June 18, 2026 at 8:32 am

    You should take a look at the SimpleMembershipProvider

    It is very easy to use it together with EF.

    Update

    For MVC4 I would start with the blank template.

    you need WebSecurity.InitializeDatabaseConnection to set up the database.

    WebSecurity.InitializeDatabaseConnection("DefaultConnection", "Users", "Id", "UserName", true);
    

    It takes as parameters a name of a connectionstring, the table, a unique identifier column and the username-column.

    The model I use for this piece of code above is:

    [Table("Users")]
    public class User
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
    
        [Required]
        public string UserName { get; set; }
    
        public string Email { get; set; }
    
        public string FirstName { get; set; }
    
        public string LastName { get; set; }
    }
    

    To log someone in:

     WebSecurity.Login(aUsername, aPassword);
    

    The method above returns a bool, if it is true, login was successfull.

    In the Web.config you do not need to define a membershipProvider as it was with default ASP.NET Membership.

    If you need to gain access to the provider (to delete an account):

    var provider = (SimpleMembershipProvider) Membership.Provider;
    provider.DeleteAccount(aUsername); // Delete the account
    provider.DeleteUser(aUsername, true); // delete the user and its data
    

    For creating a new user (with my given model in this case)

    WebSecurity.CreateUserAndAccount(aUsername, aPassword, new { Email = aEmail, FirstName = aFirstName, LastName = aLastName });
    

    Benefit is, that you can now use your model for other EF classes as a foreign key without having the hassle when you want to do this with the normal asp.net membership. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I already have a fully pledged membership system and want to integrate my own
I have a simple create user wizard and custom membership provider which was taken
I have Symbolic C++ (the version that can integrate with V, there is no
How can I integrate word count into bassistance.de validation? For example, i dont want
I followed the directions in this post: how can we integrate jquery autocomplete using
I have downloaded Skype4COM from Skype so my question is, can i integrate it
Can someone suggest an ASP.NET source code editor control that I can integrate into
I am using ASP.NET 4.0 membership api in web form application. I want to
How do i configure connection string for Asp.Net Membership Provider? Do i have to
In a website, I need to integrate membership and authentication. So I want to

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.