If you have created your database, and set your connection string in web.config
to that database, then when you first go to Account/Login
it will generate the tables for you. Note that not all tables will be generated until you first create a user through "Register", then you will also see the tables starting with webpages_
EDIT If you are using the Internet Application template in MVC4 then it the default template is going to set you up with a localdb in the App_Data folder. This will be created the first time you run the application and call a database. (end edit)
Have a look at my answer here to "How do I use my own database with SimpleMembership and WebSecurity? What is MVC4 security all about?" to get an overview of SimpleMembership and how it all fits together.
Note that if you don't call Account/Login
, then the database will not initialise, therefore in certain circumstances you will need to initialise it yourself, you can use the following lines in your Application_Start
in global.asax.cs, or see my answer here to "ASP.NET MVC 4, The “WebSecurity.InitializeDatabaseConnection” method can be called only once" for more comprehensive scenarios.
if (!WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection("myConnectionStringName", "Users", "UserId", "Email", autoCreateTables: true);
}
Alternatively you can register InitializeSimpleMembership
as a global filter, which would have the same effect as using the above code in global.asax.cs.
InitializeSimpleMembership
simply does the above lines of code for you, but because it is only decorating the AccountController
in the template provided, it will only kick in if you visit one of the Actions on that controller. This is where most of us trip up the first time. The MVC Internet Application template is only providing a sample way of using it. You need to actually ensure it is used across the entire site in order to have a production ready system.
Footnote:
Now that you've started using SimpleMembership it is worth knowing straight away that it works best in a code-first scenario, and that it is easiest to immediately put the UserProfile model class into your own DbContext that you are using for all the other Models in your code; this will prevent a lot of problems for you later. I will leave you to ask more questions on this separately as it is slightly off-topic.
Note that you can use the same connection string name for both your DbContext and the SimpleMembership (by default this is called "DefaultConnection" in the visual studio project template).