0

I am using AWS SES service to send email to users. Upon registration, a token is generated in my AccountServive.sc

var confirmEmailToken = await _userManager.GenerateEmailConfirmationTokenAsync(user);

I have a function in this service SendEmailForAccountCreatedAndEmailVerification which takes the username, and link to replace the HTML body for an email. And this body is passed in the EmailSender function.

How to create link from this token that the user receives in his/her mail which can be clicked to confirm is email address?

Mansi
  • 313
  • 1
  • 5
  • 10

1 Answers1

1

The full code for generating activation link already defined under Register.cshtml.cs and RegisterConfirmation.cshtml.cs :

var userId = await _userManager.GetUserIdAsync(user);
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
EmailConfirmationUrl = Url.Page(
    "/Account/ConfirmEmail",
    pageHandler: null,
    values: new { area = "Identity", userId = userId, code = code },
    protocol: Request.Scheme);
LazZiya
  • 5,286
  • 2
  • 24
  • 37
  • I have been trying this and the variations of this. I am consistently getting an error: `The name 'Url' does not exist in the current context` Similary for Request – Mansi May 23 '20 at 08:13
  • I'm not generating link in the controller base, I'm working in the service class where I want to generate the link. That's why, Url.Action won't work – Mansi May 23 '20 at 10:15
  • So, the `ConfirmEmail` is in a different project? – LazZiya May 23 '20 at 10:20
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/214474/discussion-between-mansi-and-laz-ziya). – Mansi May 23 '20 at 10:24