简体   繁体   English

电子邮件确认ASP.NET Identity 2 OWIN MVC和API无效令牌

[英]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.

相关问题 Asp.net 身份电子邮件确认令牌的问题:“无效令牌” - Issue with Asp.net identity Email Confirmation Token: “Invalid Token” 如何在ASP.NET身份电子邮件确认中修复“无效令牌” - How to fix 'Invalid Token' on ASP.NET Identity Email Confirmation 使用 MVC 5 和 Asp.net Identity 进行电子邮件确认 - Email Confirmation with MVC 5 and Asp.net Identity 如何在ASP.NET MVC5 Identity 2中添加HTML电子邮件模板以进行电子邮件确认? - How can i add html email template for email confirmation in asp.net mvc5 identity 2? 没有OWIN和AspNet.Identity的基于Asp.Net Web Api令牌的授权 - Asp.Net Web Api Token Based Authorization WITHOUT OWIN and AspNet.Identity Asp.net OWIN身份刷新令牌和令牌过期 - Asp.net OWIN Identity refresh tokens and token expiration Asp.Net身份OWIN Facebook ExternalLoginInfo电子邮件始终为空 - Asp.Net Identity OWIN Facebook ExternalLoginInfo Email is always null ASP.NET Identity 2.2.1 - 发送包含代码的确认电子邮件,而不是链接 - ASP.NET Identity 2.2.1 - send confirmation email with code, not with link ASP.net 身份框架 - 重新发送确认电子邮件 - ASP.net Identity Framework - Resend Confirmation Email 没有ASP.NET身份的电子邮件确认和密码策略 - Email confirmation and Password Policy Without ASP.NET Identity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM