0

I want to implement email / account confirmation via email while user registration. But have difficulties with the following method, creation correct callbackUrl and a way how it should confirmed by application. Is there a best way to solve that? I got the following resources: this and this

    [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)
        {
            var 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 this link: <a href=\"" 
                                               + callbackUrl + "\">link</a>");
            // ViewBag.Link = callbackUrl;   // Used only for initial demo.
            return View("DisplayEmail");
        }
        AddErrors(result);
    }

    // If we got this far, something failed, redisplay form
    return View(model);
}
bisecom
  • 1
  • 1
  • Sorry, but I haven't understood what is your problem. Could you clarify? – Steve May 11 '20 at 20:35
  • Hello Steve! How to build callbackUrl properly for webapi? When the confirmation link comes to user and user clicks it, does web api standard controller has methods to catch the registration data? – bisecom May 12 '20 at 09:28
  • Gentlemen, any idea on these pls? – bisecom May 13 '20 at 11:59
  • 1
    Probably has been solved here https://stackoverflow.com/questions/25245065/asp-net-web-api-generate-url-using-url-action – Steve May 13 '20 at 12:03

0 Answers0