从已发送的电子邮件网络核心身份调用时,重置密码不起作用
Resetting password isn't working when it's called from a sent email net core identity
在 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");
但我正在做的是在注册新用户时,应用程序会生成一个自定义的随机密码并将其发送给用户,然后告诉用户单击此处重置密码。
当点击 link 时,它会将用户带到一个几乎空白的页面,只有一句话:“必须实施重置密码的代码”,如下图所示。
这是注册页面中的代码:
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);
电子邮件确认邮件工作正常,但显示重置密码 link
this
我该如何解决这个问题?
尝试将变量名passwordToken改为code
在 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");
但我正在做的是在注册新用户时,应用程序会生成一个自定义的随机密码并将其发送给用户,然后告诉用户单击此处重置密码。 当点击 link 时,它会将用户带到一个几乎空白的页面,只有一句话:“必须实施重置密码的代码”,如下图所示。
这是注册页面中的代码:
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);
电子邮件确认邮件工作正常,但显示重置密码 link this
我该如何解决这个问题?
尝试将变量名passwordToken改为code