Ok, so I setup SimpleMembership, and I was under the impression that I had to run WebSecurity.InitializeDatabaseConnection(...)
only once in order to have it set up the database. Later, when I attempt to look up a user id, I get an error telling me that I need to initialize the database before I ever call WebSecurity. Ok... so I put the initialization call back into _ViewStart.cshtml as it suggested. Now I run again and I get the error The "WebSecurity.InitializeDatabaseConnection" method can be called only once.
So I'm damned if I do damned if I don't.
Can someone explain this to me?
You need to place the WebSecurity.InitializeDatabaseConnection(...)
in the DatabaseInit method of the DatabaseConfig App_Start\DatabaseConfig.cs
class like below:
public static void DatabaseInit(string ConnectionName = "DefaultConnection", string userTable = "UserProfile", string userIdColumn = "UserId", string userNameColumn = "UserName", bool autoCreateTable = true)
{
WebSecurity.InitializeDatabaseConnection(ConnectionName, userTable, userIdColumn, userNameColumn, autoCreateTables: autoCreateTable);
}
Hope this helps :)