Search

Thursday, April 9, 2015
0 comments

How to create new user in ASP.NET 4.5

9:01 AMThursday, April 9, 2015
I have already explain custom registration control in asp.net on my blog. Now,A very simple method provided by the Microsoft in DOTNET Framework 4.5 for create new users. Using "Microsoft.AspNet.Identity" namespace you can create new users also implementing role init. This namespace is available in "Microsoft.AspNet.Identity.Core" assembly. Username and password are the primary field of registration so first of all, we will store the username by the textbox in "IUser" interface.  In this assembly IUser interface property is inherited by the IdentityUser class and this class is inherited by the ApplicationUser class. So we can easily access the UserName property of the IUser interface in ApplicationUser class.

var user = new ApplicationUser() { UserName = UserName.Text };

By this line of code, we can store the unique username in the database using the connection string, which is available in ApplicationDbContext  class. Now after retrieving the username, should go for second step that is store password in UserManager class using Create method( ), which is take some parameters such as

Create(ApplicationUser user, String Password);

Now, Retrieved result will store in IdentityResult class. Using Succeeded property of that class, we will check that username and password.
Now, the complete code is 

var manager = new UserManager();

var user = new ApplicationUser() { UserName = UserName.Text };

IdentityResult result = manager.Create(user, Password.Text);

Code generate the following output

How to create new user in ASP.NET 4.5

  In the next article i will show you how to add custom fields or you can say how to customized it.
Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top