Note that there are some explanatory texts on larger screens.

plurals
  1. POWebSecurity.ConfirmAccount(Id) is always false
    text
    copied!<p>Ive got a problem: my websecurity always throws false on confirmation. What am I doing wrong? Here is my Validate Action(Ive debugged it, the id received is the right confirmation token:</p> <pre><code> public ActionResult Validate(String Id) { if (String.IsNullOrEmpty(Id)) { return View(); } bool b = WebSecurity.ConfirmAccount(Id); if (b) { return View("ConfirmationSuccess"); } return View("ConfirmationFailure"); } </code></pre> <p>And here is my registration action:</p> <pre><code> public ActionResult Register(RegisterModel model, string ReturnUrl) { if (ModelState.IsValid) { // Попытка зарегистрировать пользователя try { string confirmationToken = WebSecurity.CreateUserAndAccount(model.rEmail.ToLower(), model.rPassword, null, true); dynamic email = new Email("~/Views/Emails/RegisterConfirmation.cshtml"); email.To = model.rEmail; email.ConfirmationToken = confirmationToken; email.Send(); return RedirectToAction("EmailValidation", new { Email = model.rEmail.ToLower() }); } catch (MembershipCreateUserException e) { string field = string.Empty; switch (e.StatusCode) { case MembershipCreateStatus.DuplicateUserName: field = "rEmail"; break; case MembershipCreateStatus.InvalidPassword: field = "rPassword"; break; default: field = "RegisterForm"; break; } ModelState.AddModelError(field, ErrorCodeToString(e.StatusCode)); } } ViewBag.RegisterModel = model; ViewBag.ReturnUrl = ReturnUrl; ViewBag.LoginModel = new LoginModel(); //ModelState.AddModelError("rEmail", "Пользователь с таким e-mail уже зарегистрирован"); // Появление этого сообщения означает наличие ошибки; повторное отображение формы return View("Login"); } </code></pre> <p>after registration the email is sent, the link is the right link, but when It goes to WebSecurity.ConfirmAccount(Id), it always throws false....</p> <p>Thank you for your time and sorry for my bad English.</p> <p>UPD: There is a converter for all urls to lower on my IIS server. Could it be the case, that it compares keys case-sensitive? And how can I fix this?</p> <p>UPD: Ok, the problem is really in lowercase url. WebSecurity.ConfirmAccount is case-sensitive... Ive made a little workaround in my action so that I could get the right ConfitmtionToken, but this is not fully right way, while there could be two identical ConfirmationToken.ToLower() as I think, So, please, somebody, point me the right way to do it. And here is my workaround:</p> <pre><code>public ActionResult Validate(String Id) { if (String.IsNullOrEmpty(Id)) { return View(); } //bool b = WebSecurity.ConfirmAccount(Id); using (var ctx = new DBContext()) { Id = ctx.wpMembership.Where(s =&gt; s.ConfirmationToken.Equals(Id, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().ConfirmationToken; } if (WebSecurity.ConfirmAccount(Id)) { return View("ConfirmationSuccess"); } return View("ConfirmationFailure"); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload