简体   繁体   中英

ASP.NET Core Identity at Register page, register then wait 5 minutes and more

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM