Using Asp.Net mvc 3 simple Login system

4/1/2014

Asp.Net provide users forms authentication for login system. It contains database schemas, sample code, stored procedure, views, database roles. C# code is very simple, however database setup takes lots of time. In additional you have to deploy database correctly, looks like contains bug if you just get all the script, stored procedure, views, roles and etc. Asp.net 3 login system works if just attach the mdf file. Anyway, this blog shows you have to enable simple login authentication system by using asp.net 3.

 

First step, when using visual studio, select mvc 3 and with internet type to generate project.

MVC 3 template project

 

after created the asp.net application, config contains following database setting. and if you run the application, default action will create the local mdf file which contains everything for running asp.net login system.

1
2
3
4
5
<add name="ApplicationServices" connectionstring="
         Data Source=YourDatabaseServer;         
         Initial Catalog=ASPNETDB.MDF;         
         Integrated Security=SSPI;" providername="System.Data.SqlClient">
</add>

This's the default database connection string setting.

1
2
3
4
5
<add name="ApplicationServices" connectionstring="
         data source=.\SQLEXPRESS;
         Integrated Security=SSPI;
         AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providername="System.Data.SqlClient">
</add>

The easiliest is deploy the mdf to the your online sql database server. Then you don't need to generate all the scripts from above database microsoft created.