AutoCreate SimpleMembership tables in ASP.NET MVC4
This article describes about to SimpleMembership of WebMatrix.Authenication and authorization are very needed part of web application. SimpleMembership, introduced with WebMatrix, tries to address these issues by offering a flexible model for authenticating the users.
In this article I will explain how to integrate with existing database and issues confronted during development.
You can also have a look on MVC related article here:
Smart Working With Custom Value Providers in ASP.Net MVC
EXECUTION ORDER OF FILTERS IN MVC 4 WITH PRACTICES: IMPORTANT FAQ
Invoke Action With Model Binders in MVC
Extension Helpers Method in MVC
Custom Button With TagBuilder Using MVC Razor Engine
CALL CONTROLLER ACTION METHOD FROM JQUERY USING AJAX
EXECUTION ORDER OF FILTERS IN MVC 4 WITH PRACTICES: IMPORTANT FAQ
REMOVE AMBIGUTY OF CONTROLLER NAMES IN MVC APPLICATION
Precompiled Razor View Using RazorGenerator MVC and PreCompiledViewEngine in MVC 4
Step1: I have created an internet application though I have already built in database in SqlServer 2008.
Step2: Select internet application from project template as shown in below image:
This is the default structure of application as shown in below image:
Step3: I have an existing database where I want to integrate SimpleMemberShip as shown in depicted below image:
I’ve created a table Users with few columns in an existing database. Columns such as ID and UserName are important for us which I will be talking about down the level in this article.
Step4: There are 4 files where i will be concentrating more during this article as shown in depicted image below:
Step5: Open you web.config and put this connection string in the connectionString tag as shown in depicted image below:
and configure these lines just behind the Authentication mode tag to enable SimpleMembershipProvider and roleManager as shown in below image:
Step6: Now open AccountModel.cs and change the RegisterModel as per our need, I added a new property Email into model to meet my requirement as shown below in image:
Step7: Open AccountController class and you will see that it has already decorated with an Annotation InitializeSimpleMembership .This class executes first to AccountController and responsible for Database creration if it doesn’t exist and also creates simple membership tables by connecting to database .Kindly see an image depicted below;
Step8: We are done with all configuration setup, now run an application and click on register button on the right top as shown in below image:
As soon as you click on register button it initialize InitializeSimpleMembership class and performs the steps to create SimpleMembership .Kindly see an image below:
Step9: Fill the required details and register the user as shown in image below:
Step10: All the information related to employee has been stored in database in two tables as well as user “dotnet” logged in user in web site. Kindly see an image shown below:
In next article I will tell you about some error which I encountered during this development.
Hope you learned SimpleMemberShip.
Note: Friends I am not able to upload sample application which I have created due to it exceeds the limit of 10 MB .This application is built up in VS 2012.So please keep in touch base with me on Sachin.kalia15@gmail.com or drop your message on Dotnetpiper.com.
Hope you enjoyed and it may help you down the line.
Keep coding and Smile
0 comments :
Post a Comment