asp.Net   发布时间:2022-04-07  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了asp.net – .NET身份电子邮件/用户名更改大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
有谁知道如何让用户使用电子邮件确认更改使用ASP.NET身份的用户名/电子邮件?有很多关于如何更改密码的例子,但是我找不到任何内容。

解决方法

这应该为你做点窍门:
// get user object from the storage
var user = await useRMANager.FindByIdAsync(userId);

// change username and email
user.Username = "NewUsername";
user.Email = "New@email.com";

// Persiste the changes
await useRMANager.updateAsync(user);

// generage email confirmation code
var emailConfirmationCode = await useRMANager.GenerateEmailConfirmationTokenAsync(user.Id);

// generate url for page where you can confirm the email
var callBACkurl= "http://example.com/ConfirmEmail";

// append userId and confirmation code as parameters to the url
callBACkurl += String.Format("?userId={0}&code={1}",user.Id,httpUtility.UrlEncode(emailConfirmationCodE));

var htmlContent = String.Format(
        @"Thank you for updating your email. Please confirm the email by clicking this link: 
        <br><a href='{0}'>Confirm new email</a>",callBACkurl);

// send email to the user with the confirmation link
await useRMANager.SendEmailAsync(user.Id,subject: "Email confirmation",body: htmlContent);



// then this is the action to confirm the email on the user
// link in the email should be poinTing here
public async Task<ActionResult> ConfirmEmail(String userId,String codE)
{
    var confirmResult = await useRMANager.ConfirmEmailAsync(userId,codE);

    return RedirectToAction("Index");
}

大佬总结

以上是大佬教程为你收集整理的asp.net – .NET身份电子邮件/用户名更改全部内容,希望文章能够帮你解决asp.net – .NET身份电子邮件/用户名更改所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。