I’m exploring ASP.NET MVC 4 these days. I will be pleased if someone can help by answering my question .
I am building an academic project \"Project management and s
Follow the answer on similar question to the link below. If you have any more questions let me know.
Similar Question with answer
Update
After reading your first comment, sounds like you need to first understand what MVC is all about before you touch on SimpleMembership. try the following links.
wikipedia
w3schools
MSDN
http://www.asp.net/mvc
with SimpleMembership there are 2 ways for storing and using that information for authentication.
you may use default (UserProfiles) table, that is in database pointed to by "DefaultConnection" string.
you may use YOUR database and a table therein to be used as replacement of default UserProfiles table.
option 1 is explained very well elsewhere. for option 2 follow steps given below: suppose your database context is mDbContext and table that you want to use for replacement of UserProfiles is Employees.
your Employee model looks like this
namespace m.Models
{
public class Employee
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Mobile { get; set; }
public Designation Designation { get; set; }
.........
your DbContext looks like this
namespace m.Models
{
public class mDBContext : DbContext
{
DbSet<Employee> Employees { get; set; }
......
you need to tell WebSecurity to use your database.
WebSecurity.InitializeDatabaseConnection("mDBContext",
"Employees", "ID", "UserName", autoCreateTables: true);
add additional fields in RegisterModel class in AccountModels
public class RegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Mobile { get; set; }
public Designation Designation { get; set; }
}
In AccountController Register method for HttpPost replace
WebSecurity.CreateUserAndAccount(model.UserName, model.
with
WebSecurity.CreateUserAndAccount(model.UserName, model.Password,
new { FirstName = model.FirstName, LastName = model.LastName,
Mobile = model.Mobile});
rebuild and update database if pending any changes (or add migrations).