我是MVC4的新手。我想从忘记密码表单发送更改密码表单的链接。当我在忘记密码表单中单击重置按钮时,它应该发送更改密码的绝对URL。现在我忘记密码的链接是:// localhost:59523 / Login / Forgotpassword?Length = 5.现在我想发送一个链接到用户链接:// localhost:59523 / Login / Changepassword。请帮我。提前谢谢。
这是我的控制器代码:
MailMessage mail = new MailMessage();
mail.To.Add(_check_email);
mail.From = new MailAddress("sample@gmail.com");
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");
答案 0 :(得分:2)
试试这个:
string absolute_url = Url.Action("Changepassword", "Login", null, Request.Url.Scheme);