저는 ASP.NET MVC를 처음 접했고 특히 현재 등록 프로세스를 수정해야합니다. 성공적으로 등록되면 사용자 이메일과 사용자 이름을 사용하여 다른 데이터베이스의 다른 테이블에 INSERT를 수행합니다. 지금까지 내가 찾은 다른 것들은 내가 필요로하지 않는 데이터 검증을 등록하거나 변경하기 위해 필드를 추가하는 것이기 때문에 이것을 구체적으로 달성 할 수있는 방법을 찾지 못했습니다.ASP.NET MVC 5 사용자 등록을 사용자 정의하여 다른 데이터베이스에 연결
또한이 작업을 수행하는 저장 프로 시저를 만들었지 만 어떤 방법이 더 좋은지 잘 모릅니다.
IdentityModel.cs
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("UsersConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
public class ZivoyDbContext : IdentityDbContext<ApplicationUser>
{
public ZivoyDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ZivoyDbContext Create()
{
return new ZivoyDbContext();
}
}
그리고 심지어이 작업을 수행하는 방법을 모르는 계정 컨트롤러
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
//Insert into another table
ZivoyDbContext.Users.Add();
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
// string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
// await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
, 사람이 어떻게 작동하는지 설명해 주 시겠어요? SQL Server에 연결하는 MVC 5를 검색했지만 거의 모든 대답은 단일 연결을 사용하는 단일 컨트롤러 또는 ADO.NET을 사용하는 단일 컨트롤러에 해당합니다.
실제 질문은 무엇입니까? 작동하지 않는 것은 무엇입니까? – Rik
@Rik 다른 데이터베이스의 다른 테이블에 사용자 데이터를 삽입하는 방법을 모르겠다. 시도한 코드는 아무 것도하지 않지만 다른 예제에서 본 것을 시도했다. 어디서 INSERT INTO ... 부분을 만들어야합니까? –
이 튜토리얼을 확인하십시오 - EF6이라고 생각합니다 - 데이터를 추가하는 데 도움이되는지 확인하려면 다음을 수행하십시오. http://www.entityframeworktutorial.net/EntityFramework4.3/add-entity-using-dbcontext.aspx – EtherDragon