public async Task <ActionResult> Register(RegisterViewModel model, string returnUrl) { //do not use userManager to create users use the house service, it will create profile for you if (ModelState.IsValid) { var user = Mapper.Map <OldHouseUser>(model); var result = await MyService.CreateUserWithProfile(user, new HashSet <string> { OldHouseUserProfile.PROFILENBAME }); if (result.IsSuccessful) { var loginClaim = await MyService.MyUserManager.Login(model.UserName, model.Password, DateTime.Now.AddDays(7)); if (loginClaim != null) { Jtext103AuthMiddleware <OldHouseUser> .Login(HttpContext.GetOwinContext().Environment, loginClaim); } return(RedirectToLocal(returnUrl)); } else { AddErrors(result); } } // 如果我们进行到这一步时某个地方出错,则重新显示表单 return(View(model)); }