1

I have a web server running asp.net core 2.2 web api, and an angular client.

Now, I use this code to generate email confirmation links:

var uriBuilder = new UriBuilder("http://example.com/confirmEmail");
var parameters = HttpUtility.ParseQueryString(string.Empty);
parameters["id"] = user.Id.ToString();
parameters["token"] = token;
uriBuilder.Query = parameters.ToString();

Uri finalUrl = uriBuilder.Uri;

But I think that it is not the best practice. How shoudl I do it instead?

Hugo
  • 349
  • 3
  • 6
  • 23

1 Answers1

2

I use something like this. I think it's good point!

var code = await _userManager.GenerateEmailConfirmationTokenAsync(identityUser);
var callbackUrl = Url.Action(
                        "ConfirmEmail",
                        "Account",
                        new { userId = identityUser.Id, code = code },
                        protocol: HttpContext.Request.Scheme);

await emailService.SendEmailAsync(model.Email, "Confirm your account",
                        $"confirm email: <a href='{callbackUrl}'>link</a>");

Sorry I didn't notice that you need use absolute url, but I think it have to help you. https://stackoverflow.com/a/37609162/8006943

evilGenius
  • 1,041
  • 1
  • 7
  • 16
  • It's not work for me. My web server(localhost:9800) is isolated from the internet, my amgular client(example.com) routes the request to the web server. Your solution will be have url like localhost:9800/api/account/confirmemail*****, but i need url like example.com/confirmemail**** – AndreyTimofeev Jun 11 '19 at 06:07