There are a lot of ways how you can implement it. For example:
add bool IsAgentA
to your RegisterModel class
in AccountModels.cs
public class RegisterModel
{
[Required]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
[DataType(DataType.Password)]
public string ConfirmPassword { get; set; }
public bool IsAgentA {get; set;}
}
Add radio buttons for IsAgentA
in your Registration View
(Yes - Agent A, No - Agent b). I will not write it here.
And after that modify your Register ActionResult
in AccountController
as follows:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
try
{
WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
WebSecurity.Login(model.UserName, model.Password);
if (model.IsAgentA)
{
Roles.AddUserToRole(model.UserName, "Role A"); // user in role A
}
else
{
Roles.AddUserToRole(model.UserName, "Role B"); // user in role B
}
return RedirectToAction("Index", "Home");
}
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
}
}
return View(model);
}