用户注册后如何根据角色将用户重定向到不同的页面
我试图在没有任何运气的情况下将以下内容实施到帐户控制器中。
// POST: /Account/Register
[AllowAnonymous]
[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);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
Roles.AddUserToRole(model.UserName, model.Role);
{
if (Roles.IsUserInRole("Student"))
{
return RedirectToAction("create, "Student");
}
else if (Roles.IsUserInRole("Teacher"))
{
return RedirectToAction("create, "Teacher");
}
return RedirectToAction("index", "Home");
}
List<SelectListItem> list = new List<SelectListItem>();
SelectListItem item;
foreach (String role in Roles.GetAllRoles())
{
item = new SelectListItem { Text = role, Value = role };
list.Add(item);
}
ViewBag.roleList = (IEnumerable<SelectListItem>)list;
ModelState.AddModelError("", ErrorCodeToString(createStatus));
// If we got this far, something failed, redisplay form
return View(model);
}
}
}
欢迎任何帮助或建议