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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:57:29+00:00 2026-06-13T07:57:29+00:00

Can SimpleMembership be used with EF model-first ? When I try it, I get

  • 0

Can SimpleMembership be used with EF model-first? When I try it, I get “Unable to find the requested .NET Framework Data Provider” when I call WebSecurity.InitializeDatabaseConnection.

To put it another way: I can’t get the call to WebSecurity.InitializeDatabaseConnection to work when the connection string employs the System.Data.EntityClient provider (as it does when using the model-first paradigm).

To repro the issue, create an MVC 4 app, and replace the code-first UserProfile entity class (which you get for free with the MVC 4 template) with a model-first User class that you have created in the Entity Designer:

  1. Create an MVC 4 app in VS 2012 and add a new, blank Entity Data
    Model.
  2. Add a new Entity named User to the model, with fields for Id,
    UserName, and FullName. So, at this point, the User data entity is
    mapped to a Users table and is accessed via a funky connection
    string that employs the System.Data.EntityClient provider.
  3. Verify that the EF can access the User entity. One easy way to do
    that is to scaffold out a Users controller based on the User table
    and its associated DbContext.
  4. Edit the AccountModels.cs file to remove the UserProfile class and
    its associated UsersContext class. Replace the references to the
    (now missing) UserProfile and UsersContext classes with references
    to your new User class and its associated DbContext class.
  5. Move the call to InitializeDatabaseConnection from the
    InitializeSimpleMembershipAttribute filter class to the
    Application_Start method in Global.asax.cs. While you’re at it,
    modify the arguments to use your new User entity’s connection
    string, table name, and UserId column name.
  6. Delete the (no longer used) InitializeSimpleMembershipAttribute
    class and the references to it.

When you run the repro, it will get an Exception at the call to InitializeDatabaseConnection.

Bob

  • 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-13T07:57:30+00:00Added an answer on June 13, 2026 at 7:57 am

    SimpleMembership can work with model first. Here is the solution.

    1.InitializeSimpleMembershipAttribute.cs from MVC 4 Internet Application templete should look like this

    namespace WebAndAPILayer.Filters
    {
        [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
        public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute
        {
            private static SimpleMembershipInitializer _initializer;
            private static object _initializerLock = new object();
            private static bool _isInitialized;
    
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                // Ensure ASP.NET Simple Membership is initialized only once per app start
                LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock);
            }
    
            private class SimpleMembershipInitializer
            {
                public SimpleMembershipInitializer()
                {
                    try
                    {
                        WebSecurity.InitializeDatabaseConnection("ConnStringForWebSecurity", "UserProfile", "Id", "UserName", autoCreateTables: true);
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException("Something is wrong", ex);
                    }
                }
            }
        }
    }
    

    2.Delete CodeFirst Classes from AcountModel.cs

    3.Fix AccountCotroler.cs to work with your Model-first DbContext (ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) method)

    4.Define your "ConnStringForWebSecurity" connection string which is not same as that funky conn string for model-first db access, notice that we use provider System.Data.SqlClient not System.Data.EntityClient

     <connectionStrings>
             <add name="ModelFirstEntityFramework" connectionString="metadata=res://*/Context.csdl|res://*/Context.ssdl|res://*/Context.msl;provider=System.Data.SqlClient;provider
     connection string=&quot;data source=.\SQLEXPRESS;Initial
     Catalog=aspnet-MVC4;Integrated
     Security=SSPI;multipleactiveresultsets=True;App=EntityFramework&quot;"
     providerName="System.Data.EntityClient" />
             <add name="ConnStringForWebSecurity" connectionString="data source=.\SQLEXPRESS;Initial Catalog=aspnet-MVC4;Integrated
     Security=SSPI" providerName="System.Data.SqlClient" />
           </connectionStrings>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can find why i get this error can someone help? package Android.data; public class
Using Code First Entity Framework with .NET MVC 4 I have created a new
First I am really new to .NET framework and all stuff around. What I
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can any one tell, how to get the result of LINQ query contains group
I'm stating to figure out SimpleMembership for my ASP.Net MVC 4 site. I've augmented
I am using the built-in SimpleMembership of the ASP.net MVC4 template and want to
How can you specify the # of failed logon attempts with the default simplemembership
Is there an AD SimpleMemberShip provider for MVC4? Or a good third party one
Can't seem to figure out what's wrong with the simple getJSON call below. It's

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.