Reputation: 347
I am new to MVC4. I want to send a link for change password form from forgot password form. When i am clicking reset button in Forgot password form it should send a absolute url for change password. Now my link in forgot password is ://localhost:59523/Login/Forgotpassword?Length=5.Now I want to send a link to user link ://localhost:59523/Login/Changepassword. Please help me. Thanks in advance.
This is my controller code:
MailMessage mail = new MailMessage();
mail.To.Add(_check_email);
mail.From = new MailAddress("[email protected]");
mail.Subject = ("Reset Your Password");
var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var random_code = new Random();
var code = new string(
Enumerable.Repeat(chars, 8)
.Select(s => s[random_code.Next(s.Length)])
.ToArray());
//storing password reset code into database
var query = db.Tbl_Users.Where(u => u.ResetPwdCode ==code).FirstOrDefault();
query.ResetPwdCode = code;
db.SaveChanges();
string absolute_url = ---------->>>>>Here is the problem
string link = absolute_url + "?=" + code;
string htmlBody;
htmlBody ="Mail Body";
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
mail.IsBodyHtml = true;
mail.Body = htmlBody;
smtp.Send(mail);
ModelState.AddModelError("", "Check your mail to reset your password");
return View("Forgotpassword");
Upvotes: 0
Views: 794
Reputation: 4100
Try this:
string absolute_url = Url.Action("Changepassword", "Login", null, Request.Url.Scheme);
Upvotes: 2