简体   繁体   中英

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. The user account is created successfully, and a validation email is sent.

If i validate the token in a web api Controller it works. If I validate the token in a mvc controller it does not, I'm not sure what I've got wrong.

The error returned from the MVC controller is "Invalid token" The api and mvc run on different ports and exist in separate assemblies.

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

To fix I added matching machineKey to web.config for both api and mvc projects. Email Validation began working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM