나는이 이유 때문에 새로운 MVC와 Simplemembership Provider를 좋아합니다. 모델을 asp.net 계정 모델과 쉽게 결합 할 수 있습니다.
기본 인터넷 템플릿을 사용하면 UsersContext라는 컨텍스트가 만들어집니다. 데이터베이스에서 추적하기 위해 UserProfile 객체에 필드를 추가하는 것과 같은 간단한 작업을 수행하려면 3 가지 간단한 작업을 수행해야합니다. (기본 템플릿을 사용하는 경우 계정 모델)
- 새로운 필드 추가, 계정 컨트롤러의 레지스터 행동 모델에
을 속성을 추가 IE :
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
var db = new UsersContext();
// Attempt to register the user
try
{
WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { FirstName = model.FirstName, LastName = model.LastName, Address = model.Address, Company = model.Company, Phone = model.Phone, Country = model.Country, City = model.City, State = model.State, Zip = model.Zip });
WebSecurity.Login(model.UserName, model.Password);
return RedirectToAction("Index", "Dashboard");
}
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
전달 된 모델에서 값을 가져 와서 모델에 일치시킨 새 키워드를 주목하십시오. 모든 정보가이 완벽하게 처음 일할 때 나는 거의 울었다
을 필요로 전달하는 레지스터보기 및 모델 변경)
3 (모델은 5 월 바인딩 또는 여기에 작동하지 않을 수 있지만, 나는 아직 테스트하지 않은 경우) 이상한 오류는 없습니다.
행운을 빌어 요.