为什么我的电子邮件确认令牌无效?



我正在尝试在Microsoft身份 2.0 上获得干净的电子邮件确认。我正在生成用于确认的电子邮件链接,但它不起作用。 我发现,回调上的编码令牌正在更改为小写,我认为存在问题。但我不知道如何解决它.....

当代码变量获取值时,它看起来像: CfDJ8C5jg3XNISFEoFA015AdmTmmbOmQG/cxNBfdOALg4WM+iU6uf8WeJ13buFIzbdlP3tK3kWU1Q6BwGh/DY7dAYqbj+zz7jXGOK1Y79mtDT2jiEKV4NdaLbfaruzOvoKSVhvg4EFVYPAQRrjcAnOkfCxlff6hMVhIBWHkg8rqv7GBnqXvJ+UbCErqlobIxI69YreNWVTM1Z4lkAYQM2xmwRA//0T53KNPTWIX52oDc52eFLJAlsWhXI9uHwgfwTt0X9g==

回调后更改为: cfdj8c5jg3xnisfeofa015admtmmbomqg%2Fcxnbfdoalg4wm%2Biu6uf8wej13bufizbdlp3tk3kwu1q6bwgh%2Fdy7dayqbj%2Bzz7jxgok1y79mtdt2jiekv4ndalbfaruzovoksvhvg4efvypaqrrjcanokfcxlff6hmvhibwhkg8rqv7gbnqxvj%2Bubcerqlobixi69yrenwvtm1z4lkayqm2xmwra%2F%2F%2F0t53knptwix52odc52efljalswhxi9uhwgfwtt0x9g%3D%3D

在确认操作中,我将令牌解码为: cfdj8c5jg3xnisfeofa015admtmmbomqg/cxnbfdoalg4wm+iU6uf8WEJ13bufizbdlp3tk3kwu1q6bwgh/dy7dayqbj+zz7jxgok1y79mtdt2jiekv4ndalbfaruzovoksvhvg4efvypaqrrjcanokfcxlff6hmvhhkg8rqv7gbnqxvj+ubcRqlobixi69yRENWvtm1z4lkayqm2xmwra//0t53knptwix52odc52eFLJalswhXI9uhwgfWT0x9g==

注册.cshtml的一部分.cs

var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.Page(
"/Account/ConfirmEmail",
pageHandler: null,
values: new { userId = user.Id, code = codeenc },
protocol: Request.Scheme
);
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

confirmemail.cshtml.cs

var user = await _userManager.FindByIdAsync(userId);
if (user == null)
{
return NotFound($"Unable to load user with ID '{userId}'.");
}
var result = await _userManager.ConfirmEmailAsync(user, code);

那么我哪里犯了错误呢?

我不确定,但你试过这个吗?
code = System.Web.HttpUtility.UrlEncode(code);

问题出在我的启动.cs文件中,

options.LowercaseQueryStrings = true;

评论令牌工作正常后。

相关内容

  • 没有找到相关文章

最新更新