title: ASP.NET Core Identity - Confirm email return url
body: <p>I've managed to set up SignUp and LogIn for my project with ASP.NET Core Identity. Everything works fine but there is a small thing really bugging me.</p>
  <p>Since it is a simple project I don't want to configure account confirmation by really sending email to the user so I'm using the default templates, the user is redirected to the Account.RegisterConfirmation where they can select a link to have the account confirmed which redirects the user to the /Identity/Account/ConfirmEmail which is a blank page with the title only. I don't like it. After selecting a link to confirm the account I'd like to redirect the user to the /Account/Login. But where do I set that up?</p>
  <p>This is what I've tried so far: Add&gt;New Scaffolded Item&gt;Identity&gt;Account/ConfirmEmail(file to override) and I now I have ConfirmEmail.cshtml.cs:</p>
  <pre><code>[AllowAnonymous]
      public class ConfirmEmailModel : PageModel
      {
          private readonly UserManager&lt;IdentityUser&gt; _userManager;
  
          public ConfirmEmailModel(UserManager&lt;IdentityUser&gt; userManager)
          {
              _userManager = userManager;
          }
  
          [TempData]
          public string StatusMessage { get; set; }
  
          public async Task&lt;IActionResult&gt; OnGetAsync(string userId, string code)
          {
              if (userId == null || code == null)
              {
                  return RedirectToPage(&quot;/Index&quot;);
              }
  
              var user = await _userManager.FindByIdAsync(userId);
              if (user == null)
              {
                  return NotFound($&quot;Unable to load user with ID '{userId}'.&quot;);
              }
  
              code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
              var result = await _userManager.ConfirmEmailAsync(user, code);
              StatusMessage = result.Succeeded ? &quot;Thank you for confirming your email.&quot; : &quot;Error confirming your email.&quot;;
              return Page();
          }
      }
  </code></pre>
  <p>Changing <code>return Page();</code> to <code>return RedirectToPage(&quot;/Account/Login&quot;);</code> results in <strong>InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'Project.Areas.Identity.Pages.Account.ConfirmEmailModel'.</strong></p>
  <p>Where do I set up the return url to /Account/Login after the email is confirmed?</p>
  <p>I also tried without Scaffolding and overriding Account/ConfirmEmail, in Register.cshtml.cs there is</p>
  <pre><code> var callbackUrl = Url.Page(
                          &quot;/Account/ConfirmEmail&quot;,
                          pageHandler: null,
                          values: new { area = &quot;Identity&quot;, userId = user.Id, code = code, returnUrl = returnUrl },
                          protocol: Request.Scheme);
  </code></pre>
  <p>and I tried changing <code> returnUrl = returnUrl</code> to <code>returnUrl = &quot;~/Account/Login&quot; </code>, it didn't work.</p>
  <p>**** UPDATE ***</p>
  <p>Since I don't need email confirmation for such a simple project I just added this</p>
  <pre><code>options.SignIn.RequireConfirmedAccount = false
  </code></pre>
  <p>to the Startup class so account confirmation nor email confirmation is needed.</p>
  <pre><code>services.AddDefaultIdentity&lt;ApplicationUser&gt;(options =&gt; options.SignIn.RequireConfirmedAccount = false)
                      .AddEntityFrameworkStores&lt;ProjectContext&gt;();
  
  
  services.Configure&lt;IdentityOptions&gt;(options =&gt;
  {
      options.SignIn.RequireConfirmedEmail = false;
      options.SignIn.RequireConfirmedAccount = false;
  });
  </code></pre>