asp.net-mvc – 使用ASP.NET身份重置密码时的令牌无效

我通过复制vs2013模板中的代码在我的mvc应用程序中实现了asp.net身份.基本的是工作,但是我didnet得到重置密码工作.当我发送忘记密码页面时,会生成包含令牌的电子邮件.该方法返回此令牌
UserManager.GeneratePasswordResetTokenAsync(user.Id)

看起来像这样:

当我点击链接时,重置密码打开,让用户输入电子邮件地址和新密码.然后调用更改密码:

UserManager.ResetPasswordAsync(user.Id,model.Code,model.Password);

这对我看起来不错,但结果总是一个“无效的令牌”,我没有得到它:)

有人有一个想法为什么它不工作?地狱是哪里存储的令牌?我认为它必须在数据库中和AspNetUsers表中.

谢谢.

解决方法

UserManager在asp.net idebtity中生成的令牌通常包含“”字符,当作为查询字符串传递时,该字符串更改为URL中的“”(空格).在您的ResetPassword ActionResult中,将“”替换为“”,如下所示:
var code = model.Code.Replace(" ","+");
//And then change the following line 
UserManager.ResetPasswordAsync(user.Id,model.Password);
//To this one so it uses the code(spaces replaced with "+") instead of model.Code
UserManager.ResetPasswordAsync(user.Id,code,model.Password);

这应该够了吧
我有同样的问题,找到答案here.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....