I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component public class AllViewComponent : ViewComponent { private readonly UserManager<ApplicationUser> _userManager; public AllViewComponent(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IViewComponentResult> InvokeAsync() { List<StudentViewModel> allUsers = new List<StudentViewModel>(); var items = await _userManager.Users.ToListAsync(); foreach (var item in items) { allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email }); }
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.
In the next article i will show you how to add custom fields or you can say how to customized it.
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
In the next article i will show you how to add custom fields or you can say how to customized it.
Comments
Post a Comment