ASP.NET Core Identity at Register page, register then wait 5 minutes and more
I use Microsoft.AspNetCore.Identity.EntityFrameworkCore
version 5.0.0-preview.7 , .NET Core 5.0-preview , Visual Studio 2019 preview community edition, Blazor server-side.
I check database, something written to database
After press submit, I wait 10 minutes at this screen. (and still wait more, no error at dotnet console screen).
What is wrong?
ASP.NET Core Identity at Register page, register then wait 5 minutes and more
If you implement and use custom EmailSender service to send email notification to register user, which would cause above issue once EmailSender service takes long time to send email.
To troubleshoot the issue and determine if something wrong with send mail process, you can try to write some custom log to trace the execution time of key code snippet, like below.
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
//custom log 1
_logger.LogInformation($"Reached Into Register Method - {DateTime.UtcNow.ToString()}");
returnUrl = returnUrl ?? Url.Content("~/");
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
if (ModelState.IsValid)
{
var user = new IdentityUser { UserName = Input.Email, Email = Input.Email };
var result = await _userManager.CreateAsync(user, Input.Password);
if (result.Succeeded)
{
_logger.LogInformation("User created a new account with password.");
//custom log 2
_logger.LogInformation($"Created New User - {DateTime.UtcNow.ToString()}");
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
var callbackUrl = Url.Page(
"/Account/ConfirmEmail",
pageHandler: null,
values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
protocol: Request.Scheme);
//custom log 3
_logger.LogInformation($"Generated Email Token - {DateTime.UtcNow.ToString()}");
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
//custom log 4
_logger.LogInformation($"Sent Email - {DateTime.UtcNow.ToString()}");
if (_userManager.Options.SignIn.RequireConfirmedAccount)
{
//...
In my test, if my custom EmailSender service takes about 2 minutes to send registration notification, browser user has to wait a long time for this operation.
Logs of user registration
In browser Network tab, it take about 2 minutes