问题描述
我有两个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
现在我的问题
-
工程在本地主机和QA罚款。在测试OK SSL的本地主机了。
-
在生产(使用SSL)失败。从WCF生成令牌和MVC验证失败。
- 生成,并在同一个应用程序的工作验证。
这是怎么回事无效标记
错误出现?有的web.config
什么关系呢?
发现问题。
这是在应用程序池在IIS中。我使用WCF和MVC应用程序不同的应用程序池。现在我把它放在同一个应用程序池并工作正常。
其他信息:对于那些有同样的问题,我的解决方案不能解决问题,那么你可能想尝试的machineKey
。 p>
的
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
Works fine in localhost and qa. Tested ok on SSL in localhost too.
Fails on Production (uses SSL). Generating token from WCF and validating in MVC fails.
- 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身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!