Click here to Skip to main content
15,878,871 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody,

I try to implement the function recover email. I get the email with link for recover passsword, like this: http://localhost:41787/Account/ResetPassword?rt=cgUuxE3xpVnjkQEkpif73Q2[^] ,

And i also see that in the datbase there isa PasswordVerificationToken

But if I past the link in the browser I get this error:


Error.
An error occurred while processing your request.

THis is my method:



C#
// POST: /Account/ForgotPassword
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);
                MembershipUser userEmail;

                using (var context = new LolaBikeContext())
      {
         var foundUserName = (from u in context.userProfiles
                              where u.Email == model.Email
                              select u.UserName).FirstOrDefault();
         if (foundUserName != null)
         {
            userEmail = Membership.GetUser(foundUserName.ToString());
         }
         else
         {
            user = null;
         }
      }
      if (user != null)
      {
         // Generae password token that will be used in the email link to authenticate user
         var token = WebSecurity.GeneratePasswordResetToken(user.UserName);
         // Generate the html link sent via email
         string resetLink = "<a href='"
            + Url.Action("ResetPassword", "Account", new { rt = token }, "http") 
            + "'>Reset Password Link</a>";
 
         // Email stuff
         string subject = "Reset your password for asdf.com";
         string body = "You link: " + resetLink;
         string from = "email";
 
         MailMessage message = new MailMessage(from, model.Email);
         message.Subject = subject;
         message.Body = body;
         SmtpClient client = new SmtpClient
        {
            Host = "smtp.sendgrid.net",
            Port = portnumber,
            EnableSsl = false,
            UseDefaultCredentials = false,
            Credentials = new System.Net.NetworkCredential("username", "password"),
            DeliveryMethod = SmtpDeliveryMethod.Network
      };
 
         // Attempt to send the email
         try
         {
            client.Send(message);
         }
         catch (Exception e)
         {
            ModelState.AddModelError("", "Issue sending email: " + e.Message);
         }
      }         


               
               
                return View("ForgotPasswordConfirmation");
               //TempData["Message"] = "User Not exist.";
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }


Thank you
Posted
Updated 20-Apr-15 4:07am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900