public ActionResult Register(RegisterModel model)
 {
     // 尝试注册用户
         try
         {
             WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
             //WebSecurity.Login(model.UserName, model.Password);
             return Json(new { success = true, msg = "Add " +model.UserName + " success!" });
         }
         catch (MembershipCreateUserException e)
         {
             return Json(new { success = false, msg = "Add " + model.UserName + " fail: " + e.Message });
         }
 }
Beispiel #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // 尝试注册用户
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return View(model);
        }