私は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