Hi everyone,
I'm trying to implement a password reset method:
protected void ResetPassword(object sender, EventArgs e) { var userStore = new UserStore<IdentityUser>(); var userManager = new UserManager<IdentityUser>(userStore); // Register Token Provider var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("Account"); userManager.UserTokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<IdentityUser>(provider.Create("PasswordReset")); var user = userManager.FindByName(UserName.Text); if (user != null) { string passwordResetToken = userManager.GeneratePasswordResetToken(user.Id); //Now what do I do with this token? LoginForm.Visible = false; LoginStatus.Visible = true; lblStatus.Text = "A password token has been emailed to you."; } else { lblStatus.Text = "Invalid username."; lblStatus.ForeColor = Color.Red; LoginStatus.Visible = true; } }
I've been following instructions on various websites but can't figure out what I should do with the password reset token that has been generated. According to Account Confirmation and Password Recovery with ASP.NET Identity, I'm supposed to do like:
var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { UserId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>");
My questions:
1. What does Url.Action do?
2. I was getting an error "The name 'Url' does not exist in the current context." So I added the namespace
using System.Security.Policy;
..but now I get "System.Security.Policy.Url does not contain a definition for 'Action'.
3. How do I implement just a simple method where a temporary password is emailed to the user and she just needs to enter in the temporary password, then enter her new password?
Thanks very much.