2016-05-24 26 views
1

私はASP.NET MVC 5アイデンティティテンプレートを使用して、ユーザー登録ASPNET MVC 5アイデンティティ確認ユーザー登録

// POST: /Account/Register 
    [HttpPost] 
    [AllowAnonymous] 
    [ValidateAntiForgeryToken] 
    public async Task<ActionResult> Register(RegisterViewModel model) 
    { 
     if (ModelState.IsValid) 
     { 
      // bind viewModel --> Model 
      var user = new ApplicationUser 
      { 
       UserName = model.Email, 
       Email = model.Email, 
       Fio = model.Fio, 
       Street = model.Street, 
       ... 
      }; 

      var result = await UserManager.CreateAsync(user, model.Password); 
      if (result.Succeeded) 
      { 
       await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); 

       // 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); 
       ... 

ためAccountControllerの標準的な方法であると私は、ユーザ登録を確認するためにcallbackUrlを使用しています。

は、その後、私はユーザーとしてブラウザにそのURLを入れて、登録証明:私は自分のアプリケーションの1つのインスタンスから両方の方法(登録と確認を)置くとき、それは仕事、そう

// GET: /Account/ConfirmEmail 
    [AllowAnonymous] 
    public async Task<ActionResult> ConfirmEmail(string userId, string code) 
    { 
     if (userId == null || code == null) 
     { 
      return View("Error"); 
     } 
     var result = await UserManager.ConfirmEmailAsync(userId, code); 
     return View(result.Succeeded ? "ConfirmEmail" : "Error"); 
    } 

を。 しかし、2つのインスタンスを持ち、最初のインスタンスに登録して2番目のインスタンスで確認すると、ConfirmEmailAsyncメソッドが間違った結果を返します。

私はUserManagerがデータベースに接続するためのストアを持っていなければならず、サイトの別のインスタンスから電子メールをチェックできると思います。これは正しい?

答えて

1

あなたのweb.configmachineKeyを入れて、アプリケーションのすべてのインスタンスで同じキーを使用する必要があります。

+1

うわー!出来た!ありがとう)) –

+0

@АлександрШабунинそれが動作する場合は、答えを受け入れてください – trailmax

関連する問題