asp.net – .NET身份电子邮件/用户名更改
发布时间:2020-05-23 11:19:27 所属栏目:asp.Net 来源:互联网
导读:有谁知道如何让用户使用电子邮件确认更改使用ASP.NET身份的用户名/电子邮件?有很多关于如何更改密码的例子,但是我找不到任何内容。 这应该为你做点窍门: // get user object from the storagevar user = await userManager.FindByIdAsync(userId);// chang
|
有谁知道如何让用户使用电子邮件确认更改使用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 – 如果表单字段为空,如何将NULL插入数据库
- asp.net-mvc – Kendo:处理Ajax数据请求中的错误
- asp.net-mvc – 如何在.net MVC中使用Flux和事件发射器?
- asp.net-mvc – 使用disabled =“disabled”属性创建一个Se
- asp.net-mvc – 如何传递列表从控制器到MVC 3中查看
- asp.net-mvc – 处理asp.net mvc中的错误和异常
- asp.net-mvc-4 – 如何在asp.net MVC4查看页面中包含javasc
- asp.net – #Eval if语句在中继器
- ASP.Net MVC,使用javascript提交表单
- asp.net – CheckBoxList多个选择:难度模型绑定
推荐文章
站长推荐
- asp.net-mvc – mvc创建我自己的html帮助器,如何
- 如何在Asp.Net页面中包含Javascript文件
- asp.net – 从IEnumerable获取不同的项目
- iis-7 – ASP.NET应用程序吃内存. Application /
- 无法在ASP.NET VB站点中加载System.DirectorySer
- asp.net核心 – ASP.NET核心中的基本身份验证
- asp.net-mvc-3 – 是否可以强制使用DataType作为
- asp.net上传文件到数据库的解决方案
- asp.net-mvc – 在您的ViewModel中放置什么
- asp.net-mvc – MVC3 AntiForgeryToken打破了Aja
热点阅读
