Showing posts with label websecurity. Show all posts
Showing posts with label websecurity. Show all posts

Thursday, August 1, 2013

WebSecurity.InitializeDatabaseConnection method can be called only once

After setting up SimpleMembership, I noticed this error every time I landed on an account page in my project.  The fix for this is:

1.  Create an _AppStart.cshtml in the root of your project and put this code:

@{
   if (!WebSecurity.Initialized) {
        WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", true);
    }
}


2.  Open the file InitializeSimpleMembershipAttribute.cs under the Filters folder and comment out this line:


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


Hope that helps!