asp.net – .NET身份电子邮件/用户名更改
发布时间:2020-12-15 18:48:45 所属栏目:asp.Net 来源:网络整理
导读:有谁知道如何让用户使用电子邮件确认更改使用ASP.NET身份的用户名/电子邮件?有很多关于如何更改密码的例子,但是我找不到任何内容。 解决方法 这应该为你做点窍门: // get user object from the storagevar user = await userManager.FindByIdAsync(userId
有谁知道如何让用户使用电子邮件确认更改使用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-mvc – MVC6自托管wwwroot内容返回404,IIS Express
- asp.net-mvc – ASP.NET MVC 4移动显示模式停止工作
- asp.net – 实体框架如何决定是引用现有对象还是创建新对象
- asp.net – Shutterfly Order API.
- asp.net – 在TableRowCollection上使用linq
- ASP.NET FileUpload:如何在选择文件后自动回复?
- .net – 如何检查用户是属于AD组还是嵌套组?
- asp.net – 将webgrid导出为pdf asp mvc razor
- asp.net-mvc-4 – 返回Web API中的自定义错误对象
- 用AJAX实现的无刷新的分页实现代码(asp.net)
推荐文章
站长推荐
热点阅读