gpt4 book ai didi

c# - 从已发送的电子邮件网络核心身份调用时,重置密码不起作用

转载 作者:行者123 更新时间:2023-12-05 04:42:14 25 4
gpt4 key购买 nike

在 mvc 应用程序中使用 .net 5 我搭建了 Identity 并且在 ResetPassword 页面中重置密码的代码运行良好,代码如下:

 var code = await _userManager.GeneratePasswordResetTokenAsync(user);
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
var callbackUrl = Url.Page(
"/Account/ResetPassword",
pageHandler: null,
values: new { area = "Identity", code },
protocol: Request.Scheme);

await _emailSender.SendEmailAsync(
Input.Email,
"Reset Password",
$"Please reset your password by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

return RedirectToPage("./ForgotPasswordConfirmation");

但我正在做的是在注册新用户时,应用程序会生成一个自定义的随 secret 码并将其发送给用户,然后告诉用户单击此处重置密码。当点击链接时,它会将用户带到一个几乎空白的页面,只有一句话:“必须实现重置密码的代码”,如下图所示。

这是注册页面的代码:

  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);

var passwordToken = await _userManager.GeneratePasswordResetTokenAsync(user);
passwordToken = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(passwordToken));
var resetPasswordCallbackUrl = Url.Page(
"/Account/ResetPassword",
pageHandler: null,
values: new { area = "Identity", passwordToken },
protocol: Request.Scheme);

await _emailSender.SendEmailAsync(
Input.Email,
$"You have been registered in bla bla",
$"<p> your password is </p><p>\"{Input.Password}\"</p>\n to change it please click<a href ='{HtmlEncoder.Default.Encode(resetPasswordCallbackUrl)}'>here </a>");

await _emailSender.SendEmailAsync(Input.Email, "please confirm your email",
$"please confirm your email by clicking <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>here</a>.");

return LocalRedirect(returnUrl);

电子邮件确认邮件工作正常,但显示重置密码链接 this

我该如何解决这个问题?

最佳答案

尝试将变量名passwordToken改为code

关于c# - 从已发送的电子邮件网络核心身份调用时,重置密码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69880343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com