public ActionResult Register(string username, string password)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus Status;
Membership.CreateUser(username,password,null, null, null, true, null, out Status);
//WebSecurity.CreateUserAndAccount(username, password);
if (Status == MembershipCreateStatus.Success)
{
Roles.AddUserToRole(username, "Mechanic");
FormsAuthentication.SetAuthCookie(username, false);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", ErrorCodeToString(Status));
}
return RedirectToAction("Mechanics", "Mechanic");
}
// If we got this far, something failed, redisplay form
return View();
}
答案 0 :(得分:0)
您可以在此方法调用周围放置一个try / catch并检查异常:
try
{
Membership.CreateUser(username,password,null, null, null, true, null, out Status);
}
catch (Exception ex)
{
... put the breakpoint here and inspect the exception
}