Email Confirmation Error Invalid Token AspNet Identity

ぃ、小莉子 提交于 2020-01-06 02:07:44

问题


I have two Web applications, WCF and MVC which share same database. I am using Aspnet Identity 2.0

While registering new user, it creates confirmation token and sends email to the user. Creating token, sending email is mostly done in WCF, verification is done in MVC application.

var code = UserManager.GenerateEmailConfirmationToken(user.Id);
string.Format("{0}/Account/ConfirmEmail?userId={1}&code={2}", WebsiteUrl, 
   HttpUtility.UrlEncode(user.Id), HttpUtility.UrlEncode(codeId));

I am using same Data Protection Provider

In WCF

var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("MyTestApplication");
UserManager.UserTokenProvider =
                new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<ApplicationUser>(
                    provider.Create("UserToken"))
                {
                    TokenLifespan = TimeSpan.FromDays(7)
                };

In MVC

var dataProtectionProvider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("MyTestApplication");
manager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("UserToken"))
                {
                    TokenLifespan = TimeSpan.FromDays(7)
                };
            }

Source : Make ASP.NET Identity 2.0 Email confirm token work for WCF and MVC

Now to my Problem

  1. Works fine in localhost and qa. Tested ok on SSL in localhost too.

  2. Fails on Production (uses SSL). Generating token from WCF and validating in MVC fails.

  3. Generating and Validating in same Application works.

How is this invalid token error occuring? Has web.config anything to do with it?


回答1:


Found the problem.

It was the application pools in IIS. I was using different application pool for WCF and MVC application. Now i put it in same application pool and is working fine.

Additional Info: For those having same problem and my solution doesn't fix the problem then you might want to try machineKey.

http://gunaatita.com/blog/Invalid-Token-Error-on-Email-Confirmation-in-Aspnet-Identity/1056

PS. I almost always find answer myself after i post it on stackoverflow. Thank you.



来源:https://stackoverflow.com/questions/30615467/email-confirmation-error-invalid-token-aspnet-identity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!