Robie w moim panelu logowania zakładke "Przypomnij hasło". Problem pojawia się w linijce:
user = Membership.GetUser(foundUserName.ToString());
Za każdym razem zwraca NULL mimo że "foundUserName" zawiera prawidłową wartość. Czytałem że ".GetUser" działa tylko dla użytkowników zalogowanych..jak to można obejść? Prosze o pomoc.
Ponizej kod:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult _Retrieval(RetrievalModel model)
{
if (ModelState.IsValid)
{
MembershipUser user;
using (var context = new EFDbContext())
{
var foundUserName = (from u in context.UserProfile
where u.eMail == model.eMail
select u.UserName).FirstOrDefault();
if (foundUserName != null)
{
user = 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 test@tests.com"";
string body = "You link: " + resetLink;
string from = "test@tests.com";
MailMessage message = new MailMessage(from, model.eMail);
message.Subject = subject;
message.Body = body;
SmtpClient client = new SmtpClient();
// Attempt to send the email
try
{
client.Send(message);
}
catch (Exception e)
{
ModelState.AddModelError("", "Issue sending email: " + e.Message);
}
}
else
{
ModelState.AddModelError("", "No user found by that email.");
}
}
return View();
}