Introduction
This article explains the following
- How to create an ASP.NET MVC Project
- How to Add ADO.NET Entity Data Model
- How to Add a Controller
- How to validate User Credentials
- How to keep User Details in Sessions and display them in the User Dashboard
1. Design your Database
Create the UserProfile table using the following script.
Insert user records using the following script.
2. Create Project
Go to File, New, then click on Project.
![create project]()
Select Visual C#, Web under Installed templates. After that, select ASP.NET MVC 4 Web Application, then mention the Application Name (MvcLoginAppDemo) and Solution Name as you wish, then click OK.
![ASP.NET MVC 4 Web Application]()
Under Project template, select a template as Basic, then view the engine as Razor. Click OK.
![select a template as Basic]()
3. Add Entity Data Model
Go to Solution Explorer, right-click on Project, Add, then select ADO.NET Entity Data Model.
![select ADO.NET Entity Data Model]()
Give it a meaningful model name, and then click on Add.
![sampleDataModel]()
Select Generate from the database and then click on Next.
![Generate from database]()
Click on New Connection.
![New Connection]()
After clicking on New Connection, we have to provide the following Connection Properties in the following wizard.
- Provide the Server name.
- Select the "Use SQL Server Authentication" radio button.
- Enter the Username and Password in the password text box.
- Check the "Save my password" checkbox.
- Select the "Select or enter a database name:" radio button.
- Select the database to which you want to set the connection.
- Click on the "Test Connection" button to ensure the connection can be established.
- Then click OK.
![Test Connection]()
Select the radio button, and yes, include the sensitive data in the connection string.
![Choose your data connection]()
Choose your database objects, as in the following image.
![Choose your database objects]()
Click on Finish. At this point UserProfie entity will be created.
![UserProfie]()
4. Add a Controller
Go to Solution Explorer, right-click on the Controller folder, Add, and then click on Controller.
( Or ) Simply use shortcut key Ctrl + M, Ctrl + C,
![Add a Controller]()
Provide the Controller Name and Scaffolding template as Empty MVC Controller. Then click on Add.
![Empty MVC Controller]()
Write the following code in HomeController.
5. Create Views
Create View for Login Action Method
Right-click on the Login Action method, then click on Add View, as in the following picture.
![Create Views]()
Create a Strongly Typed View
- View Name must be an action method name.
- Select the view engine as Razor.
- Select Create a strongly typed view CheckBox.
- Select Model class as UserProfile (MvcLoginAppDemo)
- Select the Scaffold template as Empty
- Click on Add
![add view]()
Write the following code in Login.cshtml (view).
Create View for UserDashBoard Action method same as login view. And write the following code in UserDashBoard.cshtml (View).
6. Set as StartUp Page
Go to Solution Explorer, Project, App_Start, then RouteConfig.cs, and change the action name from Index to Login (Login. cshtml as start-up page).
![Set as StartUp Page]()
7. Run the Application
![Run the Application]()
Provide the user credentials and click on OK. If you provide valid user credentials, then the user name will be displayed on your dashboard.
![user dashboard]()
Read my articles on SSRS: http://www.c-sharpcorner.com/UploadFile/44fb93/ssrs-tutorial-part-5-embedded-datasets/
I hope you enjoyed it.