I have developed MVC web app. Now, I want to use custom form authentication into it.
For simplicity I’m using SQL membership provider for registration stuff. But, I dont want to create other custom table and map membership table to that because I just need to create simple module i need to stick with default tables
I have generated sql membership table using Aspnet_regsql tool
Now in AccountModel.cs into RegisterModel class i have added two more fields like :
public class RegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[Display(Name = "First name")]
public string FirstName { get; set; }
[Required]
[Display(Name = "Last name")]
public string LastName { get; set; }
}
Also updated dbo.aspnet_Membership table and added two more fields firstname and lastname
Now inside Controllers in AccountController.cs
code :
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
}
}
Here as CreateUser is default method of membership so I’m not able to insert my custom fields (firstname and lastname )into table at the time of create user ?
How can I do this?
Ashu, after reading your requirements, i feel you should go with coding a custom provider for yourself rather than sticking with the default. The reason I say this is that the only option you have on-hand to achieve your requirements is by following @Mystere Man’s solution.
Now, if you are going to play with the membership provider, than why not make an entirely new provider for your own. It isn’t that difficult as people think it is. All you need to do is implement some abstract classes to have things accordingly.
There are tons of tutorial available online for building a custom membership provider from scratch and i am listing few them below.