电子邮件确认错误无效令牌ASPNET身份

电子邮件确认错误无效令牌ASPNET身份

本文介绍了电子邮件确认错误无效令牌ASPNET身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Web应用程序,WCF和MVC它们共享同一个数据库。我使用ASPNET标识2.0

在注册新用户时,它创建确认令牌并发送电子邮件给用户。创建令牌,发送电子邮件在WCF大多完成,核查MVC应用程序就完成了。

 变量code = UserManager.GenerateEmailConfirmationToken(user.Id);
的String.Format({0} /帐号/ ConfirmEmail用户id = {1}&安培; code = {2},WebsiteUrl,
   HttpUtility.UrlEn code(user.Id),HttpUtility.UrlEn code(codeID));

我使用同样的数据保护供应商

在WCF

  VAR提供商=新Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider(MyTestApplication);
UserManager.UserTokenProvider =
                新Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider< ApplicationUser>(
                    provider.Create(UserToken))
                {
                    TokenLifespan = TimeSpan.FromDays(7)
                };

在MVC

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

来源:Make为WCF ASP.NET 2.0身份的电子邮件中确认令牌的工作和MVC

现在我的问题


  1. 工程在本地主机和QA罚款。在测试OK SSL的本地主机了。


  2. 在生产(使用SSL)失败。从WCF生成令牌和MVC验证失败。


  3. 生成,并在同一个应用程序的工作验证。

这是怎么回事无效标记错误出现?有的web.config 什么关系呢?


解决方案

发现问题。

这是在应用程序池在IIS中。我使用WCF和MVC应用程序不同的应用程序池。现在我把它放在同一个应用程序池并工作正常。

其他信息:对于那些有同样的问题,我的解决方案不能解决问题,那么你可能想尝试的machineKey

PS。我几乎总能找到自己的回答后,我张贴在计算器。谢谢你。

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?

解决方案

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.

这篇关于电子邮件确认错误无效令牌ASPNET身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 22:37