[英]Email Confirmation ASP.NET Identity 2 OWIN MVC and API Invalid Token
I'm attempting to get ASP.NET Identity 2.0 working for email validation. 我正在尝试使ASP.NET Identity 2.0可以用于电子邮件验证。 The user account is created successfully, and a validation email is sent. 用户帐户创建成功,并发送验证电子邮件。
If i validate the token in a web api Controller it works. 如果我在Web API控制器中验证令牌,则它可以工作。 If I validate the token in a mvc controller it does not, I'm not sure what I've got wrong. 如果我在mvc控制器中验证令牌,则不会验证令牌,我不确定我错了什么。
The error returned from the MVC controller is "Invalid token" The api and mvc run on different ports and exist in separate assemblies. 从MVC控制器返回的错误是“无效令牌”。api和mvc在不同的端口上运行,并且存在于单独的程序集中。
Here is some code fragments of the relevant parts. 这是相关部分的一些代码片段。
//Startup.cs
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
//ApplicationUserManager.cs
manager.EmailService = new EmailService();
var dataProtectionProvider = options.DataProtectionProvider;
manager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
//MVC Controller
public ApplicationUserManager UserManager
{
get { return this._userManager ?? this.HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); }
private set { this._userManager = value; }
}
...
UserManager.ConfimEmailAsync(userid,ConfirmationCode)
//Web API Controller
var result = this.UserManager.ConfirmEmail(model.UserId, model.ConfirmationToken);
This post helped. 这篇文章有帮助。 ASP.NET Identity 2 - UserManager.ConfirmEmail Fails In Production ASP.NET Identity 2-UserManager.ConfirmEmail在生产中失败
To fix I added matching machineKey to web.config for both api and mvc projects. 为了解决这个问题,我为api和mvc项目将匹配的machineKey添加到web.config中。 Email Validation began working. 电子邮件验证开始工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.