Identity 2.0在这一领域拥有新功能,但没有文档。
这里发布了一篇新文章。添加新信息。http://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity
在一个空项目上安装Microsoft.AspNet.Identity.Samples包,就可以找到实现该功能的代码。示例应用程序是用MVC 编写的
我发现了一些样本代码的碎片。它们太晦涩了,我决定这篇帖子会有用。这就是生成代码和回调URL的方式:
string code = manager.GenerateEmailConfirmationToken(user.Id);
string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id);
manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href="" + callbackUrl + "">here</a>.");
这就是您在退货时的处理方式:
string code = IdentityHelper.GetCodeFromRequest(Request);
string userId = IdentityHelper.GetUserIdFromRequest(Request);
if (code != null && userId != null)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var result = manager.ConfirmEmail(userId, code);
参考文献:https://aspnet.codeplex.com/SourceControl/latest#Samples/Identity/Webforms.Samples/Webforms.Samples/Account/Confirm.aspx.cs
https://aspnet.codeplex.com/SourceControl/latest#Samples/Identity/Webforms.Samples/Webforms.Samples/Account/Register.aspx.cs